The largest Interview Solution Library on the web


Hibernate Tutorials/
« Previous | 1 | 2 | 3 | Next »
If an entity or class has collection of values for a particular variable, then we can map those values using any one of the collection interfaces available in java. Hibernate can persist instances of java.util.Map, java.util.Set, java.util.SortedMap, java.util.SortedSet, java.util.List, and any array of persistent entities or values.

Collection typeMapping and Description
java.util.SetThis is mapped with a <set> element and initialized with java.util.HashSet
java.util.SortedSetThis is mapped with a <set> element and initialized with java.util.TreeSet. The sort attribute can be set to either a comparator or natural ordering.
java.util.ListThis is mapped with a <list> element and initialized with java.util.ArrayList
java.util.CollectionThis is mapped with a <bag> or <ibag> element and initialized with java.util.ArrayList
java.util.MapThis is mapped with a <map> element and initialized with java.util.HashMap
java.util.SortedMapThis is mapped with a <map> element and initialized with java.util.TreeMap. The sort attribute can be set to either a comparator or natural ordering.

Arrays are supported by Hibernate with <primitive-array> for Java primitive value types and <array> for everything else. However, they are rarely used so I'm not going to discuss them in this tutorial.
If you want to map a user defined collection interfaces which is not directly supported by Hibernate, you need to tell Hibernate about the semantics of your custom collections which is not very easy and not recommend to be used.
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com