Generation Logic

The following table lists all types of files that can be generated by the generator. Further down you can see for which model element which file is getting generated and also how modeling options affect the generation result.

Target JavaDoc
EntityClass This is the main type of file to be generated. A generated “EntityClass” will hold data and is annotated with JPA annotations. Optionally, Java Bean Validation annotations are getting added, too.
EntityDAO A generated “EntityDAO” class contains logic to use an entity manager instance for CRUD operations. An entity DAO also is the place where you should implement custom queries. Having them in a central place fosters re-use of query functionality and leads to a better organized codebase.
EntityDAOUnitTest A generated “EntityDAOUnitTest” holds the testing logic for the corresponding generated “EntityDAO” class. The generated source file includes logic to initialize an entity manager factory and to get an instance of an entity manager. To accomplish this, the persistence units that are generated in the persistence.xml are being used.
EntityLifecycleListener An “EntityLifecycleListener” class is a class that provides mostly empty implementations for the JPA listener methods for @PrePersist, @PostPersist, @PostLoad, @PreUpdate, @PostUpdate,
EntityUnitTest A generated “EntityUnitTest” has generated setUp and tearDown methods to get an entity manager instance that is needed for testing the handling of entities. The unit test class has implemented methods for FIND, PERSIST, MERGE and REMOVE functionality.
OrmXml The generated “OrmXml” file amongst others provides the option to set a default schema name to be used by all entities that are listed in the persistence.xml from where the orm.xml file is being referenced.
PersistenceXml The generated “PersistenceXml” file lists all the entity classes and includes two persistence units. One unit for the transaction type “JTA” and one for the transaction type “RESOURCE_LOCAL”. “RESOURCE_LOCAL” is going to be used to execute unit tests outside of the application container. If you plan to use the entities outside of an application server, you can use this unit to handle persistent data in your JSE application.
TestDataGenerator A generated “TestDataGenerator” holds an implementation that is capable of creating and inserting test data into a database by using pure Java code instead of using SQL-statements. This test data is meant to be used for tests during development and should not be added to production databases.
TestDataGeneratorUnitTest A generated “TestDataGeneratorUnitTest” is meant to be used to execute the data-creation logic in the “TestDataGenerator” class.
ThreadLocalSessionData The purpose of a generated “ThreadLocalSessionData” class is to store user-related data in a thread-local in order to make this data easily available within classes where there cannot be any objects injected by means of @Inject or @EJB. An example of this are JPA entity lifecycle listeners where there is no injection functionality available. Note that starting with JPA 2.1, CDI injection is supported for lifecycle listeners.

 

Entity

Mapping Generator Mapping for Entity
Remarks
Options Option Option-Type Description
Storable Boolean If set to “false”, then the @MappedSuperclass annotation gets generated for the EntityClass.Description for platform independent DSL …
UtilityFields Boolean If set to “true”, additional fields creationTimestamp, modificationTimestamp, createdBy, modifiedBy are generated. Additionally, code gets generated in EntityLifecycleListeners, that sets values for those fields.Description for platform independent DSL …
Nature Enumerated, single valued Possible values: Static, TransactionalThis option is not used so far.Description for platform independent DSL …
Externalize Boolean This option is not used so far.Description for platform independent DSL …
Platform specific options JPA-TableName Text Generates the @Table annotation and sets the value for “name” in it.
JPA-InheritanceStrategy Enumerated, single valued Possible value: SINGLE_TABLE, TABLE_PER_CLASS, JOINEDWhen this option is set, the corresponding @InheritanceStrategy annotation gets generated.
Options for member “field”field-documentation for platform independent DSL … Transient Boolean If set to “true”, the @Transient annotation gets generated.Description for platform independent DSL …
Id Boolean If set to “true”, the @Id annotation gets generated.Description for platform independent DSL …
Length Numeric This value is going to be set in the @Column annotation as “length”. Additionally, this value is going to be set in the @Size annotation for bean validation purposes.Description for platform independent DSL …
MinimumLength Numeric This value is going to be used in the @Size annotation for bean validation purposes.Description for platform independent DSL …
Unique Boolean Leads to the setting of “unique” for the @Column annotation.Description for platform independent DSL …
Mandatory Boolean Leads to the setting of “nullable” for the @Basic annodation.Description for platform independent DSL …
PrivatelyOwned Boolean Leads to the setting of orphan removal for the @OneToMany or @OneToOne AnnotationDescription for platform independent DSL …
EnumerationType Enumerated, single valued Possible value: Ordinal, LiteralSets the value for the @Enumerated annotation.Description for platform independent DSL …
Binary Boolean If set to “true”, the @Lob annotation is getting generated.Description for platform independent DSL …
LazyLoading Boolean If set to “true”, then the @Basic annotation’s “fetch” attribute is set to FetchType.LAZY.Description for platform independent DSL …
CascadeTypes Enumerated, multi valued With this option the “cascade” attribute in the annotations @OneToMany, @OneToOne, @ManyToOne and @ManyToMany is set. This option is evaluated only for “fields”, that are of an “entity” type.Description for platform independent DSL …
OrderBy Reference, multi valued If this option is set, the @OrderBy annotation is generated. This option is only evaluated for “fields” that are of an “entity” type.Description for platform independent DSL …
RelatesTo Reference, single valued If this option is set, the “mappedBy” attribute in a @OneToOne, @OneToMany or @ManyToMany is generated.Description for platform independent DSL …
Platform specific options for member “field” JPA-ColumnName Text Leads to the setting of the “name” attribute in the @Column annotation.

 

Module

Mapping Persistence Module
Remarks
Options Option Option-Type Description
none -  -

Model

Mapping Model
Remarks
Options Option Option-Type Description
none -  -

 

Virtual Projects

A virtual project is a logical grouping of types of files to be generated. In a Virtual Developer Cloud-Connector real development projects (e.g. Eclipse projects) are assigned to virtual projects. With this the cloud-connector knows where to write the files to. Further documentation related to the virtual projects offered by the generator can be found on the Virtual Developer Portal.

Generator Options

The inner workings of a generator is not only controlled by the model itself. The generator can also be parameterized by means of so-called generator options. The documentation for the generator options can be found on the Virtual Developer Portal.

Manual Code Changes

Generated code can be manually changed without the next generation process overwriting those changes. Such changes are being made inside so-called developer areas. Developer areas are areas that are bordered by comment lines.

Here is an example of a developer area in a generated test class.

Code, that gets manually added between lines 3 (START) and 4 (ELSE), will not going to be overwritten by the generator.
Code that normally would be generated by the generator will still be visible between lines 4 (ELSE) and 5 (END), but it will be there as comments only.