
Chapter 4 Generating Hibernate Persistent Objects and JSF Pages
Mapping collections of value types
For Hibernate, there are two types of classes:
- entity type - has its own database identity (primary key value) and mapping file
- value type - has no database identity, and belongs to an entity type. Its persistent state is embedded in the table row of the owning entity type. Value type classes may also be called components
If there is a value type class on the navigable role side of an association with a multiplicity of one, PowerDesigner will embed the value type in the entity type as a composite attribute.
To map collections of value type:
- Create an entity type and a value type class.
- Create an association between them. On the value type side, set the multiplicity to one and the navigability to true.
- Open the property sheet of the value type class, and click the Hibernate tab.
- Check the Value type checkbox.
- Generate the PDM with O/R mapping.
- Open the property sheet of the entity class and click the Preview tab.
- Verify the mapping file.
A composite entity class may contain components, using the <nested-composite-element> declaration.
To define association collection type for one-to-many or many-to-many associations:
- Open the association property sheet and click the Detail tab.
- Specify a Multiplicity on both sides.
- Specify either unidirectional or bi-directional navigability.
- Specify role names if necessary.
- If one role of the association is navigable and the multiplicity is many, you can set the collection container type and batch loading size.
- If you select java.util.List or <none>, it implies that you want to use an array or list-indexed collection type. Then you should define an index column to preserve the objects collection order in the database.
Note: The Java collection container type conditions the Hibernate collection type.
Collection Container Type
|
Hibernate Collection Type
|
<None>
|
array
|
java.util.Collection
|
bag or idbag (many-to-many)
|
java.util.List
|
list
|
java.util.Set
|
set
|
Copyright (C) 2005. Sybase Inc. All rights reserved.
|
|