Trimm JPA YAML configuration reference

Below is the reference for the TRIMM Jpa YAML configuration file.
A YAML that adheres to the specification below can be used directly with the TrimmJpa Maven plugin.

Full YAML configuration file

# Setup
xmiModelPath: model/MDD Example.xml
# EA, MagicDraw, FQCN, .groovy script
#umlTool: EA
umlTool: model/CustomEAReader.groovy

basePackageName: dk.tigerteam.mddexample
generateExtensionClasses: true
# addExtensionAndBaseClassAnnotations is only valid if generateExtensionClasses is set to true
addExtensionAndBaseClassAnnotations: true
useImports: true
modelPreprocessingScript: model/model-preprocessing.groovy
collectionPropertyNameSuffix: Collection
sourceCodeFormatting:
# implementation: dk.tigerteam.trimm.mdsd.java.generator.codewriter.JalopyFormattingCodeWriter
 # Formatting exclusions can be specified even though implementation hasn't been specified (and the default JalopyFormattingCodeWriter is used)
 excludeFormattingForPackages:
 - dk.tigerteam.mddexample.meta
 - dk.tigerteam.mddexample.test

# Paths
generateBaseClassesToPath: target/generated-sources/domainmodel
generateExtensionClassesToPath: target/generated-sources/domainmodel-extensions
generateInterfacesToPath: target/generated-sources/domainmodel
generateTestClassesToPath: target/generated-sources/generated-tests
generateResourcesToPath: target/generated-sources/generated-resources

mapUmlPropertyTypes:
 - name: DateTime
 javaType: org.joda.time.DateTime
 jpaTypeConverterClass: org.joda.time.contrib.hibernate.PersistentDateTime
 - name: LocalDate
 javaType: org.joda.time.LocalDate
 jpaTypeConverterClass: org.joda.time.contrib.hibernate.PersistentLocalDate

# JPA Setup
jpaSetup:
 # Default provider (if left out) is dk.tigerteam.trimm.mdsd.jpa.hibernate.HibernateProvider
 #jpaProvider: dk.tigerteam.trimm.mdsd.jpa.eclipselink.EclipseLinkProvider
 addTableAndColumnNames: true
 # jpaNamedTablesAndColumnsNameResolver is only valid if addTableAndColumnNames is set to true
 jpaNamedTablesAndColumnsNameResolver: model/DatabaseTableNameResolver.groovy
 # resolveTableNames, resolveColumnNames and resolveAttributeOverrideColumnNames are only valid when jpaNamedTablesAndColumnsNameResolver ISN'T specified
 #resolveTableNames:
 # - defaultTableName: User
 # resolvedTableName: User_
 # - defaultTableName: By
 # resolvedTableName: By_
 #resolveColumnNames:
 # - defaultColumnName: value
 # resolvedColumnName: value_
 # - defaultColumnName: type
 # resolvedColumnName: type_
 #resolveAttributeOverrideColumnNames:
 # - defaultColumnName: value_type_somethingelse
 # resolvedColumnName: v_t_s

 #catalog: somecatalog
 #schema: someschema

 makeBaseClassesIntoMappedSuperClassesIfPossible: true
 generatePresentFieldInEmbeddables: false
 defaultToLazyFetchingForAllAssociations: true
 #useOptionalOnAssociationsWherePossible: true
 rootMappedSuperClass: dk.tigerteam.mddexample.model.AbstractEntity
 # inheritanceStrategy and idStrategy are only valid when rootMappedSuperClass ISN'T specified
 #inheritanceStrategy:
 # implementation: dk.tigerteam.mdsd.jpa.DefaultJpaInheritanceAndClazzesStrategy
 #idStrategy:
 # implementation: dk.tigerteam.mdsd.jpa.DefaultJpaIdStrategy
 # The generated ORM file will be placed in the <generateResourcesToPath>/META-INF folder and the default value is orm.xml
 #ormXmlFileName: orm.xml

# Extensions (note these listeners can also be groovy scripts containing a single class implement the GeneratorEventListener interface (or
# which extend specializations thereof)
eventListeners:
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.BidirectionalGeneratorEventListener
 - listener: dk.tigerteam.trimm.mdsd.jpa.hibernate.HibernateAssociationUnproxyListener
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.SerialVersionUIDGeneratorListener
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.PropertySugarMethodsEventListener
 - listener: dk.tigerteam.trimm.mdsd.jpa.Jpa2OrphanRemovalListener
 - listener: dk.tigerteam.trimm.mdsd.jpa.hibernate.HibernateFetchOptimizationListener
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.ToStringListener
 - listener: dk.tigerteam.trimm.mdsd.jpa.hibernate.HibernateIndexingListener
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.HashCodeAndEqualsListener
 - listener: dk.tigerteam.trimm.mdsd.java.generator.extension.CopyMethodEventListener

# Create Runtime Meta Model (is a requirement for createIntegrationTest)
createRuntimeMetaModel:
 packageName: dk.tigerteam.mddexample.meta

# Create JPA Integration tests for all entities
createIntegrationTest:
 testClassName: CompleteModelIntegrationTest
 extendsClass: dk.tigerteam.mddexample.model.BaseJpaModelTest
 testPackageName: dk.tigerteam.mddexample.model
 autoHandleTransactionsAndResources: true

Detailed explanation

See Java reference for base parameters.

ParameterExample value(s)Explanation
jpaProvider

  • dk.tigerteam.trimm.mdsd.jpa.hibernate.HibernateProvider
  • dk.tigerteam.trimm.mdsd.jpa.eclipselink.EclipseLinkProvider
  • dk.tigerteam.trimm.mdsd.jpa.openjpa.OpenJpaProvider


Specify which JPA provider that should be used during code generation
If left out then it will default to HibernateProvider.
addTableAndColumnNamestrue or falseIf you want to add table and column names
jpaNamedTablesAndColumnsNameResolvermodel/DatabaseTableNameResolver.groovyThe relative path to .groovy script file or FQCN (Fully Qulified Class Name) which implements the JpaNamedTablesAndColumnsNameResolver interface (see this post), if left empty you can specify mapping directly in file:

 resolveTableNames:
   - defaultTableName: User
     resolvedTableName: User_
   - defaultTableName: By
     resolvedTableName: By_
 resolveColumnNames:
   - defaultColumnName: value
     resolvedColumnName: value_
   - defaultColumnName: type
     resolvedColumnName: type_
 resolveAttributeOverrideColumnNames:
   - defaultColumnName: value_type_somethingelse
     resolvedColumnName: v_t_s

catalogsomecatalogWhich database catalog should be specified in the @javax.persistence.Table
Note: This parameter only has effect if you set addTableAndColumnNames to true
schemasomeschemaWhich database schema should be specified in the @javax.persistence.Table
Note: This parameter only has effect if you set addTableAndColumnNames to true
makeBaseClassesIntoMappedSuperClassesIfPossibletrue or falseShould the generator try to make base classes (according to the Base/Extension Clazz pattern) MappedSuperclass in case their only subclass is the Extension Clazz (default is true). This has the advantage of not polluting the Entity table with a discriminator column.
generatePresentFieldInEmbeddablestrue or falseShould we generate a boolean “present” field (and getter method) in Embeddable classes? If we do this, then we can save an entity with an embeddable property and get the property back, even though the embeddable instance didn’t have any properties filled (if we don’t put in present, then Hibernate et.all. will set the embeddable property to null when fetching the object from db again)
defaultToLazyFetchingForAllAssociationstrue or falseShould all associations (OneToOne, OneToMany, ManyToOne and ManyToMany) default to LAZY fetching (can be overridden using StereoTypes LAZY_LOADING_STEREOTYPE and EAGER_LOADING_STEREOTYPE) -> Default is false
useOptionalOnAssociationsWherePossibletrue or falseShould we apply “optional=true” on JPA Associations where the generator deems it possible? (This will be the cases where our association has CardinalityType.SingleOptional)
rootMappedSuperClassdk.tigerteam.mddexample.model.AbstractEntityWhat MappedSuperclass should be used for our entities (in case they don’t already have one)

This will become the root class of the entity hierarchy, unless rootSuperClass is specified.

inheritanceStrategydk.tigerteam.mdsd.jpa.DefaultJpaInheritanceAndClazzesStrategy
The FQCN (Fully Qualified Class Name) specified or the project relative path to a .groovy script, must contain a class that implements the JpaInheritanceAndClazzesStrategy interface. See this post.
If you specify the default strategy then it defaults to SINGLE_TABLE inheritance.
Note: inheritanceStrategy is only valid when rootMappedSuperClass ISN’T specified
idStrategydk.tigerteam.mdsd.jpa.DefaultJpaIdStrategy
The FQCN (Fully Qualified Class Name) specified or the project relative path to a .groovy script, must contain a class that implements the JpaIdStrategy interface. See this post.
If you specify the default strategy then it will look for an UML Property/Attribute which has the stereotype ID.
Note: idStrategy is only valid when rootMappedSuperClass ISN’T specified
ormXmlFileNameorm.xmlThe generated ORM file will be placed in the <generateResourcesToPath>/META-INF folder and the default value is orm.xml
createIntegrationTest
This will invoke the JpaUnittestCreator which create a JUnit 4 test-class which will test all of the JPA setup (mappings, etc.). For where each @Entity class that’s been generated by TRIMM JPA, the JpaUnittestCreator will create a @Test public void testPersist<ClassName>() { ...} method.

Each Test method created will create a fully valid object (graph if needed) that is persisted, then loaded again after which an object (graph) comparison will be performed to validate that persisting the object worked and didn’t loose any data.

The test class (which takes its name from the testClassName parameter and get’s placed in the package indicated by the testPackageName parameter) that gets generated MUST implement the JpaUnitTest or a subclass thereof (we recommend inheriting from AbstractModelTest). This is what get’s specified using the extendsClass parameter.

The autoHandleTransactionsAndResources parameter indicates wether the test class being generated should handle JPA resources (EntityManager closing and Transaction start and rollback) itself – or will the class that it inherits from handle this (e.g. in @Before and @After methods)

Note: createRuntimeMetaModel (see the Java YAML configuration for more) is a requirement for createIntegrationTest