Collection types in Hibernate : We can map collection elements of Persistent class in Hibernate. declare the type of collection in Persistent class from one of the following types:
1. java.util.List
2. java.util.Set
3. java.util.SortedSet
4. java.util.Map
5. java.util.SortedMap
6. java.util.Collection
or we can write the implementation of org.hibernate.usertype. UserCollectionType
The persistent class should be defined like this for collection element.
A collection is defined as a one-to-many reference. The simplest collection type in Hibernate is bag>.This collection is a list of unordered objects and can contain duplicates. This is similar to java.util.List. The content of a collection is required for a SQL query. This won’t work until the code is actually accessed. This process has a benefit that allows the developer to separate the database access logic from that of the object traversal logic. This is called lazy collection.
Filtering logic can be applied with lazy collection. This can alter the SQL which invokes when the actual collection is invoked.
Some Collection Type:
ArrayType,
Constructor: ArrayType(String role, String propertyRef, Class elementClass, boolean isEmbeddedInXML)
BagType,
Constructor: BagType(String role, String propertyRef, boolean isEmbeddedInXML)
CustomCollectionType, A custom type for mapping user-written classes that implement PersistentCollection
Constructor: CustomCollectionType(Class userTypeClass, String role, String foreignKeyPropertyName, boolean isEmbeddedInXML)
IdentifierBagType,
Constructor: IdentifierBagType(String role, String propertyRef, boolean isEmbeddedInXML)
ListType,
Constructor: ListType(String role, String propertyRef, boolean isEmbeddedInXML)
MapType,
Constructor: MapType(String role, String propertyRef, boolean isEmbeddedInXML)
SetType
Constructor: SetType(String role, String propertyRef, boolean isEmbeddedInXML)
Read More →