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.

...

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
    private List<@NotNull JpaExampleEmd> examples;
 }

Eclipse-Link

After saving an example:

...

MariaDB [controlloop]> SHOW CREATE TABLE JpaExampleObjListEc_EXAMPLES;
+------------------------------+------------------------------------------------------------------------------------------------------+
| Table                        | Create Table                                                                                         |
+------------------------------+------------------------------------------------------------------------------------------------------+
| JpaExampleObjListEc_EXAMPLES | CREATE TABLE `JpaExampleObjListEc_EXAMPLES` (
  `PRIMED` tinyint(1) DEFAULT 0,
  `timeStamp` varchar(255) DEFAULT NULL,
`child_name` varchar(255) DEFAULT NULL,
  `child_version` varchar(255) DEFAULT NULL,
  `name` varchar(120) DEFAULT NULL,
  `version` varchar(20) DEFAULT NULL,
  KEY `FK_JpaExampleObjListEc_EXAMPLES_name` (`name`,`version`),
  CONSTRAINT `FK_JpaExampleObjListEc_EXAMPLES_name` FOREIGN KEY (`name`, `version`)
REFERENCES `ExampleObjListEc` (`name`, `version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+------------------------------+------------------------------------------------------------------------------------------------------+


After saving an example:


MariaDB [controlloop]> select * from ExampleObjListEc;
+-------------+---------+
| name        | version |
+-------------+---------+
| ExampleList | 1.0.0   |
+-------------+---------+
MariaDB [controlloop]> select * from JpaExampleObjListEc_EXAMPLES;
+--------+-----------+------------+---------------+-------------+---------+
| PRIMED | timeStamp | child_name | child_version | name        | version |
+--------+-----------+------------+---------------+-------------+---------+
|   NULL | NULL      | example1   | 1.0.0         | ExampleList | 1.0.0   |
|   NULL | NULL      | example2   | 1.0.0         | ExampleList | 1.0.0   |
+--------+-----------+------------+---------------+-------------+---------+

Hibernate

MariaDB [controlloop]> SHOW CREATE TABLE JpaExampleObjListEc_EXAMPLES;
+------------------------------+------------------------------------------------------------------------------------------------------+
| Table                        | Create Table                                                                                         |
+------------------------------+------------------------------------------------------------------------------------------------------+
| JpaExampleObjListEc_EXAMPLES | CREATE TABLE `JpaExampleObjListEc_EXAMPLES` (
  `name` varchar(120) NOT NULL,
 `version` varchar(20) NOT NULL,
 `child_name` varchar(255) DEFAULT NULL,
 `child_version` varchar(255) DEFAULT NULL,
 `primed` bit(1) DEFAULT NULL,
 `timeStamp` datetime(6) DEFAULT NULL,
  KEY `FK1a58hldurq1910ne2hbm9a7af` (`name`,`version`),
  CONSTRAINT `FK1a58hldurq1910ne2hbm9a7af` FOREIGN KEY (`name`, `version`)
REFERENCES `ExampleObjListEc` (`name`, `version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+------------------------------+------------------------------------------------------------------------------------------------------+

...