Versions Compared

Key

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

Persistence classes scanning

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.

...

Code Block
languagejava
titleApplication.java
.............................
@EntityScan({"org.onap.policy.models.tosca.simple.concepts",
    "org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts"})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

...

Implications using Hibernate and SpringBoot scan

persistence.xml file doesn't contain all JPA classes in "org.onap.policy.models.tosca.simple.concepts" package, so SpringBoot will intercept additional classes (not defined into persistence.xml file) and will generate additional tables into controlloop database for them: ToscaEventFilter, ToscaModel, ToscaServiceTemplates, ToscaServiceTemplates_ToscaServiceTemplate, ToscaTimeInterval, ToscaTrigger.


Schema generation

Map of Strings


Code Block
languagejava
titleJpaExampleMap
@Embeddable
@Getter
@ToString
public class ExampleKey implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column(name = "name", length = 120)
    private String name;

    @Column(name = "version", length = 20)
    private String version;
}

@Entity
@Table(name = "ExampleMap")
@Data
@EqualsAndHashCode
public class JpaExampleMap implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    @VerifyKey
    @NotNull
    private ExampleKey key;

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


Eclipse-Link

MariaDB [controlloop]> describe ExampleMap;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| name    | varchar(120) | NO   | PRI | NULL    |       |
| version | varchar(20)  | NO   | PRI | NULL    |       |
+---------+--------------+------+-----+---------+-------+
MariaDB [controlloop]> SHOW CREATE TABLE JpaExampleMap_ATTRIBUTES;
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| Table                    | Create Table                                                                                                       |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| JpaExampleMap_ATTRIBUTES | CREATE TABLE `JpaExampleMap_ATTRIBUTES` (
`name` varchar(120) DEFAULT NULL,
  `version` varchar(20) DEFAULT NULL,
`ATTRIBUTES` longtext DEFAULT NULL,
  `ATTRIBUTES_KEY` varchar(255) DEFAULT NULL,
  KEY `FK_JpaExampleMap_ATTRIBUTES_name` (`name`,`version`),
  CONSTRAINT `FK_JpaExampleMap_ATTRIBUTES_name` FOREIGN KEY (`name`, `version`) REFERENCES `ExampleMap` (`name`, `version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+

Hibernate

to be continued

JpaToscaDataType_PROPERTIES table

Eclipse-Link

MariaDB [controlloop]> SHOW CREATE TABLE JpaToscaDataType_PROPERTIES;
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| Table                       | Create Table                                                                                                                                                                                       |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+
| JpaToscaDataType_PROPERTIES | CREATE TABLE `JpaToscaDataType_PROPERTIES` (
                                                          `name` varchar(120) DEFAULT NULL,
                                                          `version` varchar(20) DEFAULT NULL,
                                                          `PROPERTIES` longblob DEFAULT NULL,
                                                          `PROPERTIES_KEY` varchar(255) DEFAULT NULL
                                                       ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+

Currently in controlloop database, I have not found out why foreign key has not be generated in this table and in all '_PROPERTIES', '_META', '_CONSTRAINTS' tables as well.

Hibernate

to be continued

Implications using Hibernate

to be continued