Hibernate Cartridge Modeling

The page describes the modeling standards one must follow to in order to use the Hibernate Cartridge.

Supported Stereotypes

Stereotype Model Element Description
<<Entity>> Class Produces Hibernate entities.
<<Service>> Class Produces Session EJB facades for the hibernate entities.
<<Enumeration>> Class Indicates that the class will be a persistent type-safe enumeration, implemented by means of a Hibernate UserType. Any attribute modeled on this entity will result in an enumeration literal. You may assign an initial value to such an attribute, Hibernate will persist that specified value for the corresponding literal. If no such value is specified the name of the attribute is assumed. Make sure there are no naming collisions between the initial values and the attribute names you model. Please note: these enumerations use a String in order to persist their unique value.
<<Identifier>> Attribute Identifies an attribute as an identifier.
<<Unique>> Attribute Identifies an attribute as unique.
<<EmbeddedValue>> Class Identifies a class as an EmbeddedValue . This corresponds to a Hibernate component in Hibernate.

Supported Tagged Values

Entity Tagged Values

Tagged Value Used With Description
@andromda.hibernate.query An Entity operation marked as a query . Defines a hibernate query expression. Note that it's encouraged to model your query body as an OCL constraint (instead of using this tagged value).
@andromda.persistence.table <<Entity>> or a many-to many association. Defines the relational table name for entity persistence.
@andromda.persistence.column Attribute Represents the column name for entity persistence.
@andromda.persistence.column.length Attribute Represents the column length for entity persistence.
@andromda.persistence.immutable Class Identifies an <<EmbeddedValue>> as immutable .
@andromda.hibernate.inheritance <<Entity>> Used to override the default hibernate inheritance strategy defined by the hibernateInheritanceStrategy namespace property.
    Permitted values are:
  • class - table per hierarchy.
  • subclass - table per class in hierarchy.
  • concrete - Table per class.
  • union-subclass - Table per class (only on Hibernate 3).
  • interface - Root class is defined as an interface and the attributes remapped to the subclasses. This is useful in the concrete case because it has limitations in the associations.

The tagged value of @andromda.hibernate.inheritance is set on the base/root class. All subclasses must then follow the same strategy unless interface or concrete is the predecessor strategy. The default strategy is defined by the hibernateInheritanceStrategy namespace property.

@andromda.persistence.column.index Attribute The name of an index to create on an entity attribute/column.
@andromda.hibernate.formula Defines an attribute of a class as a calculated value. This tagged value stores the SQL formula that will be used to assign a value to this property. Provides the ability to specify the name to be used (if different than the actual name of the actor).
@andromda.hibernate.entity.cache <<Entity>> Defines the cache strategy for the Entity. Permited values are:
  1. read-write
  2. nonstrict-read-write
  3. read-only
@andromda.hibernate.query.useCache <<FinderMethod>> Defines is caching is enabled for this query.
@andromda.hibernate.entity.proxy <<Entity>> Defines if a proxy will be enabled for the entity. Overrrides the "hibernateProxy" namespace property.
    Permitted values are:
  • true
  • false
@andromda.hibernate.entity.dynamicInsert <<Entity>> Defines if the entity will limit the SQL insert statement to properties with values. This value overrides the namespace property for this entity.
    Permitted values are:
  • true
  • false
@andromda.hibernate.entity.dynamicUpdate <<Entity>> Defines if the entity will limit the SQL update statements to properties that are modified. This value overrides the namespace property for this entity.
    Permitted values are:
  • true
  • false
@andromda.hibernate.ehcache.maxElementsInMemory <<Entity>> EhCache property. Defines the maximum number of objects that will be created in memory.
@andromda.hibernate.ehcache.eternal <<Entity>> EhCache property. Defines if elements are eternal.
    Permitted values are:
  • true
  • false
@andromda.hibernate.ehcache.timeToIdleSeconds <<Entity>> EhCache property. Defines the time to idle for an element before it expires.
@andromda.hibernate.ehcache.timeToLiveSeconds <<Entity>> EhCache property. Defines the time to live for an element before it expires.
@andromda.hibernate.ehcache.overflowToDisk <<Entity>> EhCache property. Defines if elements can overflow to disk
    Permitted values are:
  • true
  • false
@andromda.hibernate.version <<Entity>> Specfies wheter or not the entity will have a version property. If a value is present, then the entity will have a version property with the name specified within the tagged value.
@andromda.role.name An actor with a dependency to a <<Service>> or a <<Service>> operation. Provides the ability to specify the name to be used (if different than the actual name of the actor).
@andromda.hibernate.generator.class <<Entity>> Used to define the generator class used for the hibernate entity. Any of the hibernate generator classes may be used.
    The possible options are:
  • increment
  • identity
  • sequence
  • hilo
  • seqhilo
  • uuid.hex
  • uuid.string
  • native
  • assigned
  • foreign

Service Tagged Values

Tagged Value Used With Description
@andromda.ejb.viewType <<Service>> Defines the view type for a Session EJB. If undefined, the default defined by ejbViewType will be assumed.
@andromda.ejb.transaction.type Service Operation Defines a transaction type for the method.
    Permitted values are:
  • NotSupported
  • Supports
  • Required
  • RequiresNew
  • Mandatory
  • Never

Association and Association End Tagged Values

Tagged Value Used With Description
@andromda.hibernate.lazy Association ends between <<Entity>> classes Used to denote how a relationship must be loaded: true for lazy , false for eager . Defaults to false for composite associations (unless compositionDefinesEagerLoading is set to false ) and defaults to true for the other kinds.
@andromda.hibernate.outerjoin Association ends between <<Entity>> classes Defines if Hibernate will use a outer join for fetching the given assocation end.
    Permited values are:
  • auto
  • true
  • false
For Hibernate3 this will result in a fetch clause with values:
  • join
  • select
@andromda.hibernate.association.cache Association between <<Entity>> classes Defines the cache strategy for the Association. Permited values are:
  1. read-write
  2. nonstrict-read-write
  3. read-only
@andromda.persistence.foreign.identifier AssociationEnd connecting two entities Indicates whether or not the entity should use the identifier of the foreign entity. This has the same effect as if you set @andromda.hibernate.generator.class to foreign . NOTE: that this can only be applied to the child end of a parent-child (one end is marked as composition) one-to-one association.
@andromda.persistence.assigned.identifier An attribute marked as an <<Identifier>> . Indicates whether or not the identifier is assigned (this means that the identifier is manually assigned as opposed to automatically generated). Note that setting this has the same affect as setting the @andromda.hibernate.generator.class to assigned , this is tagged value is just the preferred way as it can be applied to other frameworks besides Hibernate.
@andromda.hibernate.collection.type Association ends between <<Entity>> classes Used to define the mapping for hibernate collections. This value overrides the namespace property.
    The possible options are:
  • set
  • map
  • bag
  • list
@andromda.hibernate.sort.type Association ends between <<Entity>> classes Used to define how elements will be sorted within the collection defined by the association. (Only available for maps and sets) This value overrides the namespace property.
    The possible options are:
  • unsorted
  • natural
  • comparatorClass
@andromda.hibernate.orderByColumns Association ends between <<Entity>> classes Column names that will be used for sorting the collection, with asc or desc optionally.
@andromda.hibernate.whereClause Association ends between <<Entity>> classes Sql condition to define a subset of available data for the collection
@andromda.hibernate.collection.index Association ends between <<Entity>> classes Column containing the collection index, overrides the associationEndCollectionIndexName
@andromda.hibernate.collection.index.type Association ends between <<Entity>> classes The type of the column containing the collection index, overrides the associationEndCollectionIndexType
@andromda.persistence.column.index Association ends between <<Entity>> classes The name of an index to create on the foreign key generated by the association
@andromda.hibernate.cascade Association end between <<Entity>> classes Place an individual cascade value at an association end, overriding the properties hibernateDefaultCascade, hibernateCompositionCascade and hibernateAggregationCascade.

Additional Remarks

Dependencies can be used between Services and Entities, they won't need any stereotype assigned to them. These dependencies are used to reference an entity from another entity or service, or to reference a service from an entity or another service.

Entity query operations (i.e. finders) can be denoted by setting the query flag on the modeled operation to true (they do not require any stereotypes).

Actors represent roles within your model. To designate that a role has access to a given service you must draw a dependency from an Actor to the <<Service>>. To designate the role has access to to a given operation, you must draw a dependency from an Actor to the operation.

Transitive persistence in Hibernate is controlled by cascading Hibernate operations. There are four points to adjust that:

The idea is to visualize the cascading hierarchie by using UML composition and aggregation. The inverse direction is marked with cascade="none" to get a clear direction.