...
Currently in tosca model template, due the complexity of the schema there are some issues in foreign keys using Collections of String. The SQL code below shows the JpaToscaCapabilityAssignment_ATTRIBUTES table.
Eclipse-Link
MariaDB [controlloop]> SHOW CREATE TABLE JpaToscaCapabilityAssignment_ATTRIBUTES;
+-----------------------------------------+-------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------------------------------------+-------------------------------------------------------------------------------------------+
| JpaToscaCapabilityAssignment_ATTRIBUTES | CREATE TABLE `JpaToscaCapabilityAssignment_ATTRIBUTES` (
`name` varchar(120) DEFAULT NULL,
`version` varchar(20) DEFAULT NULL,
`ATTRIBUTES` longtext DEFAULT NULL,
`ATTRIBUTES_KEY` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-----------------------------------------+-------------------------------------------------------------------------------------------+
...
Map of Objects using ElementCollection (fixed)
The below example shows ElementCollection with embedded class. In order to avoid collisions with field names ("name" and "version"), it has been used AttributeOverride annotation to change their names.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Data @Embeddable public class JpaExampleEmd implements Serializable { private static final long serialVersionUID = 1L; @VerifyKey @NotNull @AttributeOverride(name = "name", column = @Column(name = "child_name")) @AttributeOverride(name = "version", column = @Column(name = "child_version")) private ExampleKey key; @Column private Boolean primed; @Column(name = "timeStamp", precision = 3) @Temporal(TemporalType.TIMESTAMP) @NotNull private Date timeStamp; } @Entity @Table(name = "ExampleObjMapEc") @Data public class JpaExampleObjMapEc implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId @VerifyKey @NotNull private ExampleKey key; @ElementCollection private Map<@NotNull String, @NotNull JpaExampleEmd> examples; } |
...
MariaDB [controlloop]> select * from ExampleObjMapEc;
+-----------------+---------+
| name | version |
+-----------------+---------+
| ExampleObjMapEc | 1.0.0 |
+-----------------+---------+
MariaDB [controlloop]> select * from JpaExampleObjMapEc_EXAMPLES;
+-----------------+---------+------------+---------------+--------+-----------+--------------+
| name | version | child_name | child_version | primed | timeStamp | examples_KEY |
+-----------------+---------+------------+---------------+--------+-----------+--------------+
| ExampleObjMapEc | 1.0.0 | example1 | 1.0.0 | NULL | NULL | MyKey1 |
| ExampleObjMapEc | 1.0.0 | example2 | 1.0.0 | NULL | NULL | MyKey2 |
+-----------------+---------+------------+---------------+--------+-----------+--------------+
JpaToscaDataType_PROPERTIES table
The SQL code below shows JpaToscaDataType_PROPERTIES table.
Eclipse-Link
MariaDB [controlloop]> describe JpaToscaDataType_PROPERTIES;
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| name | varchar(120) | YES | | NULL | |
| version | varchar(20) | YES | | NULL | |
| PROPERTIES | longblob | YES | | NULL | |
| PROPERTIES_KEY | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+---------+-------+
MariaDB [controlloop]> SELECT count(1) FROM `JpaToscaDataType_PROPERTIES`;
+----------+
| count(1) |
+----------+
| 41 |
+----------+
MariaDB [controlloop]> describe ToscaProperty;
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| DEFAULTVALUE | varchar(255) | YES | | NULL | |
| DESCRIPTION | varchar(255) | YES | | NULL | |
| ENTRYSCHEMA | longblob | YES | | NULL | |
| REQUIRED | tinyint(1) | YES | | 0 | |
| STATUS | int(11) | YES | | NULL | |
| parentLocalName | varchar(120) | NO | PRI | NULL | |
| localName | varchar(120) | NO | PRI | NULL | |
| parentKeyVersion | varchar(15) | NO | PRI | NULL | |
| parentKeyName | varchar(120) | NO | PRI | NULL | |
| name | varchar(120) | YES | | NULL | |
| version | varchar(20) | YES | | NULL | |
+------------------+--------------+------+-----+---------+-------+
MariaDB [controlloop]> SELECT count(1) FROM ToscaProperty;
+----------+
| count(1) |
+----------+
| 0 |
+----------+
...
Right now JpaToscaProperty will generate ToscaProperty table but this one will never used. Move Moving JpaToscaProperty as embeddable class, all max length in varchar fields will be applyapplied.
List of Objects using ElementCollection
...
List of Objects using ElementCollection (fixed)
The below example shows ElementCollection with embedded class.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@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; } |
...
Map of Objects using OneToMany
OneToMany is not used in tosca model template. The example below shows an alternative to ElementCollection. In this example there is a field names collision.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Entity @Table(name = "ExampleObjMap") @Data public class JpaExampleObjMap implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId @VerifyKey @NotNull private ExampleKey key; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @Lob private Map<@NotNull String, @NotNull JpaExample> examples; } |
...
Map of Objects using OneToMany (fixed)
The example below shows an alternative to ElementCollection with the fix to avoid field names collision.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Entity @Table(name = "ExampleObjMap") @Data public class JpaExampleObjMap implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId @VerifyKey @NotNull private ExampleKey key; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable( joinColumns = {@JoinColumn(name = "parent_name", referencedColumnName = "name"), @JoinColumn(name = "parent_version", referencedColumnName = "version")}, inverseJoinColumns = {@JoinColumn(name = "child_name", referencedColumnName = "name"), @JoinColumn(name = "child_version", referencedColumnName = "version")}) private Map<@NotNull String, @NotNull JpaExample> examples; } |
...