Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In all these tests I am using some strategies to make sure that tables and fields name generated by Hibernate will be the same as Eclipse-Link.

...

Definitions

  • ElementCollection: Specifies a collection of instances of a basic type or embeddable class. Must be specified if the collection is to be mapped by means of a collection table.
  • OneToMany: Specifies a many-valued association with one-to-many multiplicity. If the collection is defined using generics to specify the element type, the associated target entity type need not be specified; otherwise the target entity class must be specified. If the relationship is bidirectional, the mappedBy element must be used to specify the relationship field or property of the entity that is the owner of the relationship. The OneToMany annotation may be used within an embeddable class contained within an entity class to specify a relationship to a collection of entities. If the relationship is bidirectional, the mappedBy element must be used to specify the relationship field or property of the entity that is the owner of the relationship. When the collection is a java.util.Map, the cascade element and the orphanRemoval element apply to the map value.

...

Control Loop runtime uses persistence.xml file: is the deployment descriptor file for persistence using JPA. It specifies the persistence units and declares the managed persistence classes, the object/relation mapping, and the database connection details.

Hibernate

SpringBoot auto-configuration can automatically scan entity classes. In Control Loop Runtime we can use @EntityScan annotation because entity classes are not placed in the main application package or its sub-packages. In this situation, we need declare the package or list of packages in the main configuration class within @EntityScan annotation.

...

ElementCollection should be used with basic type or embeddable class, this example shows side effects using it with entity.

Code Block
languagejava
titleJpaExampleObjMapEc
collapsetrue
@Entity
@Table(name = "ExampleObjMapEc")
@Data
public class JpaExampleObjMapEc implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    @VerifyKey
    @NotNull
    private ExampleKey key;

    @ElementCollection
    @Lob
    private Map<@NotNull String, @NotNull JpaExample> examples;
}

...

ElementCollection should be used with basic type or embeddable class, this example shows side effects using it with entity.

Code Block
languagejava
titleJpaExampleObjListEc
collapsetrue
@Entity
@Table(name = "ExampleObjListEc")
@Data
public class JpaExampleObjListEc implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    @VerifyKey
    @NotNull
    private ExampleKey key;

    @ElementCollection
    @Lob
    private List<@NotNull JpaExample> examples;
}

...

Right now using Spring repositories it is possible to create more than one service template, as service templates in policy-models/tosca.

How to create additional service template (just add different name and version into the yaml file):

Code Block
languageyml
titletosca-for-smoke-testing.yaml
name: ToscaServiceTemplateSimple
version: 1.0.1
tosca_definitions_version: tosca_simple_yaml_1_3
...........................


Code Block
languagesql
titleToscaServiceTemplate
collapsetrue
MariaDB [controlloop]> select * from ToscaServiceTemplate;
+-------------+-------------------------+-------------------+----------------------+----------------------------+---------+------------------------+---------------------+----------------------+------------------+------------------+----------------------+-----------------+--------------------+--------------------------+-----------------------+-----------------------------+-------------------------------+----------------------------------+---------------------------------+
| DESCRIPTION | TOSCADEFINITIONSVERSION | derived_from_name | derived_from_version | name                       | version | capabilityTypesVersion | capabilityTypesName | dataTypesName        | dataTypesVersion | nodeTypesVersion | nodeTypesName        | policyTypesName | policyTypesVersion | relationshipTypesVersion | relationshipTypesName | topologyTemplateLocalName   | topologyTemplateParentKeyName | topologyTemplateParentKeyVersion | topologyTemplateParentLocalName |
+-------------+-------------------------+-------------------+----------------------+----------------------------+---------+------------------------+---------------------+----------------------+------------------+------------------+----------------------+-----------------+--------------------+--------------------------+-----------------------+-----------------------------+-------------------------------+----------------------------------+---------------------------------+
| NULL        | tosca_simple_yaml_1_3   | NULL              | NULL                 | ToscaServiceTemplateSimple | 1.0.0   | NULL                   | NULL                | ToscaDataTypesSimple | 1.0.0            | 1.0.0            | ToscaNodeTypesSimple | NULL            | NULL               | NULL                     | NULL                  | ToscaTopologyTemplateSimple | ToscaServiceTemplateSimple    | 1.0.0                            | NULL                            |
| NULL        | tosca_simple_yaml_1_3   | NULL              | NULL                 | ToscaServiceTemplateSimple | 1.0.1   | NULL                   | NULL                | ToscaDataTypesSimple | 1.0.0            | 1.0.0            | ToscaNodeTypesSimple | NULL            | NULL               | NULL                     | NULL                  | ToscaTopologyTemplateSimple | ToscaServiceTemplateSimple    | 1.0.0                            | NULL                            |
+-------------+-------------------------+-------------------+----------------------+----------------------------+---------+------------------------+---------------------+----------------------+------------------+------------------+----------------------+-----------------+--------------------+--------------------------+-----------------------+-----------------------------+-------------------------------+----------------------------------+---------------------------------+
MariaDB [controlloop]> select * from ToscaNodeTemplates;
+--------------------------+---------+
| name                     | version |
+--------------------------+---------+
| ToscaNodeTemplatesSimple | 1.0.0   |
+--------------------------+---------+

In the above example for ToscaNodeTemplate we are using same name and version, so the ToscaNodeTemplates table (and all other tables as well) contains only one record. Using the current entity model definition there are the follow issues:

  • There is no way to handle different configuration
  • Is impossible to delete a template in cascade, but it needs a Java code to manual delete single records in all tables

At least to avoid the above issues:

  • Avoid default name and version (for each template/node/data type, etc.. name and version have to be mandatory)
  • Java code to manual check for each table if name and version are already used