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).

output_html_m68676e23.png

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.

output_html_m36a007d5.png

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.

output_html_17984627.png

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.

output_html_m45b2e8a3.png

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.

output_html_ba416dd.png

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

output_html_387fc9c3.png

Figure 6 : @cache use example

        • Tagged Value: @table

It specifies the table name corresponding to the entity.

output_html_52b2539a.png

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.

output_html_6c7b6ad0.png

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.

output_html_m22c6d8b7.png

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.

output_html_44f3b380.png

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.

output_html_2c2622f9.png

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.

output_html_31380865.png

Figure 12 : @entity.defaultOrder use example

  • .hbm.xml result file: N/A
    • Tagged Value: @column

It stands for the column name.

output_html_m12abf772.png

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.

output_html_2679a6fc.png

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.

output_html_m3680d02c.png

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.

output_html_5edb207e.png

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.

output_html_m327bc680.png

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>

output_html_m657da70a.png

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

output_html_m2885e064.png

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.

output_html_m463ade2b.png

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

output_html_m88b7c6e.png

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

output_html_m397a6019.png

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

output_html_3e02d5b1.png

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.

output_html_41a08b0b.png

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.

output_html_6e8916f8.png

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:


  • create
  • merge
  • save-update
  • delete
  • lock
  • refresh

  • evict
  • replicate
  • all
  • none
  • delete-orphan

output_html_142572d7.png

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>


BLU AGE is a registered trademark of NETFECTIVE TECHNOLOGY S.A. - Trademarks are property of their respective owners
Do not copy or divulge without written permission