3.7.3Persistence Profile
This profile contains every possible element used as annotation in the model, in order to carry out a first transformation of the PIM « Platform Independent Model » into another model depending on the execution platform of the application to generate, the « Platform Specific Model » PSM.
These elements are features used by the persistence BSP.
Stereotypes
They stand for the annotations describing the UML model elements. They are standardized with a « MyStereotype » shape.
- The « Entity » stereotype
Used at the UML diagram class element level. This annotation is used to picture a pojo (plain old Java object) in an ORM (Object Relational Mapping) sense. This allows the persistence BSP to generate the entity implementation classes and the corresponding mapping (.hbm.xml in the examples).

Figure 1 : « Entity » stereotype use example.
- .hbm.xml result file:
<hibernate-mapping default-cascade="none">
<class name="com.netfective.howto.uml.entities.business.boss.SalutationBO" table="SALUTATION" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="assigned">
</generator>
</id>
<version name="version" type="int" column="version"/>
<property name="value" type="java.lang.String">
<column name="VALUE" not-null="true" unique="false" sql-type="CHARACTER VARYING(10)"/>
</property>
<set name="contacts" order-by="SALUTATION_FK" lazy="true" fetch="select" inverse="true">
<key foreign-key="CONTACT_SALUTATION_FKC">
<column name="SALUTATION_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.entities.business.boss.ContactBO"/>
</set>
</class>
</hibernate-mapping>
- The « Identifier » stereotype
Used for the identifier of an attribute of the persisted entity.

Figure 2 : « Identifier » stereotype use example.
- .hbm.xml result file:
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="native">
</generator>
</id>
- The Composed key :
For a table with a composed key, several class attributes may be mapped as identifier properties.
Note: The application must assign its own identifiers.

Figure 3 : composed key
- .hbm.xml result file:
<composite-id>
<key-property name="familyName" type="java.lang.String">
<column name="FAMILY_NAME" sql-type="CHARACTER VARYING(30)" not-null="true"/>
</key-property>
<key-property name="givenName" type="java.lang.String">
<column name="GIVEN_NAME" sql-type="CHARACTER VARYING(30)" not-null="true"/>
</key-property>
</composite-id>
- The « Required » stereotype :
Used to mark an attribute as required.

Figure 4 : « Required » stereotype use example.
- .hbm.xml result file:
<property name="value" type="java.lang.String">
<column name="VALUE" not-null="true" unique="true" sql-type="CHARACTER VARYING(10)"/>
</property>
- The « Unique » stereotype
Used to mark an attribute as unique.

Figure 5 : « Unique » stereotype use example.
- .hbm.xml result file:
<property name="value" type="java.lang.String">
<column name="VALUE" not-null="true" unique="true" sql-type="CHARACTER VARYING(10)"/>
</property>
- Tagged values : Entity Tagged Value
Set of values supported by the « Entity » stereotype.
- Tagged Value: @cache: Specifies the cache strategy for the entity
@cache.maxElementInMemory: Specifies the max number of cached elements
@cache.overflowToDisk: Specifies whether the cache can overflow to the disk
@cache.timeToIdleSeconds: Specifies an element inactivity period before it expires
@cache.timeToLiveSeconds: Specifies an element survival time left before it expires
@version : specifies the version column name

Figure 6 : @cache use example
- Tagged Value: @table
It specifies the table name corresponding to the entity.

Figure 7 : @table use example
<class name="com.netfective.howto.uml.entities.business.boss.AppUserBO" table="APP_USER" dynamic-insert="false" dynamic-update="false">
…
</class>
- Tagged Value: @generator.class
Defines which class is used to generate a class persistence unique identifier.

Figure 8 : @generator.class use example
- .hbm.xml result file:
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="sequence">
<param name="sequence">FRIEND_SEQ</param>
</generator>
</id>
- Tagged Value: @sequence.name
If the chosen « @generator.class» tagged value is «sequence»; which is correct for sequence implementing databases (DB2, Oracle, PostgreSQL, Interbase, etc..), the «@sequence.name» tagged value allows specifying an existing sequence in the database. This tagged value allows any character string as a value.

Figure 9 : @sequence.name use example
- .hbm.xml result file:
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="sequence">
<param name="sequence">FRIEND_SEQ</param>
</generator>
</id>
- Tagged Value: @entity.dynamicInsert
It specifies whether the SQL INSERT order shall be generated during the execution and if only columns without « null » values are allowed.

Figure 10 : @entity.dynamicInsert use example
- .hbm.xml result file:
<class name="com.netfective.howto.uml.entities.business.boss.ContactBO" table="CONTACT" dynamic-insert="true" dynamic-update="true">
…
</class>
- Tagged Value: @entity.dynamicUpdate
It specifies whether the SQL UPDATE order must be generated during the execution and if it must only contain the columns with values that have changed.

Figure 11 : @entity.dynamicUpdate use example
- .hbm.xml result file:
<class name="com.netfective.howto.uml.entities.business.boss.ContactBO" table="CONTACT" dynamic-insert="true" dynamic-update="true">
…
</class>
- Tagged Value: @entity.defaultOrder
It specifies the default order of the query list results provided by generic services.

Figure 12 : @entity.defaultOrder use example
- .hbm.xml result file: N/A
- Tagged Value: @column
It stands for the column name.

Figure 13 : @column use example
- .hbm.xml result file:
<property name="password" type="java.lang.String">
<column name="APP_ROLE" not-null="false" unique="false" sql-type="CHARACTER VARYING(1024)" index="INDEX_2"/>
</property>
- Tagged Value: @column.length
It indicates the column’s length.

Figure 14 : @column.length use example
- .hbm.xml result file:
<id name="login" type="java.lang.String" unsaved-value="null">
<column name="LOGIN" sql-type="CHARACTER VARYING(20)"/>
<generator class="native">
</generator>
</id>
- Tagged Value: @column.index
It indicates the name of an index to create on an attribute/column entity.

Figure 15 : @column.index use example
- .hbm.xml result file:
<property name="password" type="java.lang.String">
<column name="APP_ROLE" not-null="false" unique="false" sql-type="CHARACTER VARYING(1024)" index="INDEX_2"/>
</property>
- Tagged Value: @formula
This is a SQL expression defining a computed property value. These properties do not have any mapped column.

Figure 16 : @formula use example
- .hbm.xml result file:
<property name="salaryMax" type="java.lang.String" lazy="true">
<formula>SELECT MAX(salary) FROM Contact</formula>
</property>
- Tagged Value: @inheritance
It defines the inheritance strategy. Allowed values:
- class: Table by hierarchy.
- subclass: Table by class hierarchy.
- concrete: Table by concrete class.
- interface: The root class is defined as interface and its attributes are mapped again in sub-classes.
The @inheritance tagged value is set at the root class level.

Figure 17 : @inheritance=subclass use example
<class name="com.netfective.howto.uml.entities.business.boss.FriendBO" table="FRIEND" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="sequence">
<param name="sequence">FRIEND_SEQ</param>
</generator>
</id>
<version name="version" type="int" column="version"/>
<property name="label" type="java.lang.String">
<column name="LABEL" not-null="false" unique="false" sql-type="CHARACTER VARYING(10)"/>
</property>
<joined-subclass name="com.netfective.howto.uml.entities.business.boss.FavoriteFriendBO" table="FAVORITE_FRIEND" dynamic-insert="false" dynamic-update="false" abstract="false">
<key foreign-key="FAVORITE_FRIEND_INHERITANCE_FKC">
<column name="ID" sql-type="BIGINT"/>
</key>
<property name="adress" type="java.lang.String">
<column name="ADRESS" not-null="false" unique="false" sql-type="CHARACTER VARYING(50)"/>
</property>
</joined-subclass>
</class>

Figure 18 : @inheritance=class use example
<class name="com.netfective.howto.uml.entities.business.boss.FriendBO" table="FRIEND" dynamic-insert="false" dynamic-update="false">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ID" sql-type="BIGINT"/>
<generator class="sequence">
<param name="sequence">FRIEND_SEQ</param>
</generator>
</id>
<discriminator column="class" type="string"/>
<version name="version" type="int" column="version"/>
<property name="label" type="java.lang.String">
<column name="LABEL" not-null="false" unique="false" sql-type="CHARACTER VARYING(10)"/>
</property>
<subclass name="com.netfective.howto.uml.entities.business.boss.FavoriteFriendBO" discriminator-value="FavoriteFriendImpl" dynamic-insert="false" dynamic-update="false" abstract="false">
<property name="adress" type="java.lang.String">
<column name="ADRESS" not-null="false" unique="false" sql-type="CHARACTER VARYING(50)"/>
</property>
</subclass>
</class>
Association and AssociationEnd Tagged Value
- Tagged Value: @cache: Specifies the cache strategy for the entity
@cache.maxElementInMemory: Specifies the max number of cached elements
@cache.overflowToDisk: Specifies whether the cache can overflow onto the disk
@cache.timeToIdleSeconds: Specifies an element inactivity period before it expires
@cache.timeToLiveSeconds: Specifies an element survival time left before it expires

Figure 19 : @cache use example
- Tagged Value : @lazy
It indicates the way an association should be loaded: true for lazy (late initialization) and false in other cases.

Figure 20 : @lazy use example
- .hbm.xml result file:
<set name="friends" order-by="label" lazy="false" fetch="select" inverse="true" cascade="all">
<key foreign-key="FRIEND_CONTACT_FKC">
<column name="CONTACT_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.FriendBO"/>
</set>
- Tagged Value: @outerjoin
It activates the loading through outer joins.
Allowed values:
- auto
- true
- false
The clause is interpreted by the fetch attribute with those values:
- join
- select

Figure 21 : @outerjoin use example
- .hbm.xml result file:
<many-to-one name="salutation" class="com.netfective.howto.uml.associations.business.boss.SalutationBO" foreign-key="CONTACT_SALUTATION_FKC" lazy="proxy" fetch="select">
<column name="SALUTATION_FK" not-null="true" sql-type="BIGINT"/>
</many-to-one>
- Tagged Value: @collection.type
It indicates the collection mapping type.
Allowed values:
- Set
- Map
- List
- Bag

Figure 22 : @collection.type use example
- .hbm.xml result file:
<set name="favorites" order-by="CONTACT_FK" lazy="true" fetch="select" inverse="false" where="favorite = 'true'">
<key foreign-key="FRIEND_CONTACT_FKC">
<column name="CONTACT_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.FriendBO"/>
</set>
- Tagged Value: @sort.type
It indicates the way a collection elements may be sorted. Possible options:
- unsorted
- natural
- comparatorClass

Figure 23 : @sort.type use example
- .hbm.xml result file:
<set name="contacts" order-by="SALUTATION_FK" lazy="true" fetch="select" inverse="true" sort="unsorted">
<key foreign-key="CONTACT_SALUTATION_FKC">
<column name="SALUTATION_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.ContactBO"/>
</set>
- Tagged Value: @orderByColumns
It indicates the column used in the collection sort with the asc (ascending) or desc (decending) options.

Figure 24 : @orderByColumns use example
- .hbm.xml result file:
<set name="friends" order-by="label" lazy="false" fetch="select" inverse="true" cascade="all">
<key foreign-key="FRIEND_CONTACT_FKC">
<column name="CONTACT_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.FriendBO"/>
</set>
- Tagged Value: @whereClause
It indicates the SQL condition to choose data to be extracted in the collection.

Figure 25 : @whereClause use example
- .hbm.xml result file:
<set name="favorites" order-by="CONTACT_FK" lazy="true" fetch="select" inverse="false" where="favorite = 'true'">
<key foreign-key="FRIEND_CONTACT_FKC">
<column name="CONTACT_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.FriendBO"/>
</set>
- Tagged Value: @cascade
It places the association cascade attribute. Allowed values:
|
|

Figure 26 : @cascade use example
- .hbm.xml result file:
<set name="friends" order-by="label" lazy="false" fetch="select" inverse="true" cascade="all">
<key foreign-key="FRIEND_CONTACT_FKC">
<column name="CONTACT_FK" />
</key>
<one-to-many class="com.netfective.howto.uml.associations.business.boss.FriendBO"/>
</set>