Versions Compared

Key

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

...

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

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 |
+----------+

Note

Right now JpaToscaProperty will generate ToscaProperty table but this one will never used. Move JpaToscaProperty as embeddable class, all max length in varchar fields will be apply.

List of Objects using ElementCollection

...

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;
}

Eclipse-Link

MariaDB [controlloop]> describe ExampleObjListEc;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| name    | varchar(120) | NO   | PRI | NULL    |       |
| version | varchar(20)  | NO   | PRI | NULL    |       |
+---------+--------------+------+-----+---------+-------+

...

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

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 |
+------------------------------+------------------------------------------------------------------------------------------------------+

...

Code Block
languageyml
titleExample
collapsetrue
ExampleObjMap:
  name: ExampleObjMap
  version: 1.0.0
  examples:
    MyKey1:
      name: example1
      version: 1.0.0
     MyKey2:
      name: example2
      version: 1.0.0

Eclipse-Link

MariaDB [controlloop]> describe ExampleObjMap;
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| EXAMPLES | longblob     | YES  |     | NULL    |       |
| name     | varchar(120) | NO   | PRI | NULL    |       |
| version  | varchar(20)  | NO   | PRI | NULL    |       |
+----------+--------------+------+-----+---------+-------+

...

Code Block
languagejava
titleJpaExampleObjMap
collapsetrue
@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;
}

Eclipse-Link

MariaDB [controlloop]> SHOW CREATE TABLE ExampleObjMap_Example;
+-----------------------+-------------------------------------------------------------------------------------------------------------+
| Table                 | Create Table                                                                                                |
+-----------------------+-------------------------------------------------------------------------------------------------------------+
| ExampleObjMap_Example | CREATE TABLE `ExampleObjMap_Example` (
`parent_name` varchar(120) NOT NULL,
  `parent_version` varchar(20) NOT NULL,
  `child_name` varchar(120) NOT NULL,
  `child_version` varchar(20) NOT NULL,
  `EXAMPLES_KEY` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`parent_name`,`parent_version`,`child_name`,`child_version`),
  KEY `FK_ExampleObjMap_Example_child_name` (`child_name`,`child_version`),
  CONSTRAINT `FK_ExampleObjMap_Example_child_name` FOREIGN KEY (`child_name`, `child_version`)
REFERENCES `Example` (`name`, `version`),
  CONSTRAINT `FK_ExampleObjMap_Example_parent_name` FOREIGN KEY (`parent_name`, `parent_version`)
REFERENCES `ExampleObjMap` (`name`, `version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-----------------------+-------------------------------------------------------------------------------------------------------------+

...

  • The presence of longblob types used to store whole objects is definitely not so maintainable. The fix for those issues could be done in both Eclipse-Link and Hibernate. Before to apply the fix it needs to check the max length of varchar fields.
  • Document databases store all information for a given object in a single instance in the database, and every stored object can be different from every other. So, using MongoDB/Cassandra will solve all issues. JpaRepository and MongoRepository extend CrudRepository and expose the capabilities of the underlying persistence technology in addition to the rather generic persistence technology-agnostic interfaces like e.g. CrudRepository.

...