91-9990449935 0120-4256464 |
Mapping Set in Collection MappingIf our persistent class has Set object, we can map the Set by set element in the mapping file. The set element doesn't require index element. The one difference between List and Set is that, it stores only unique values. Let's see how we can implement the set in the mapping file: Example of mapping set in collection mappingIn this example, we are going to see full example of collection mapping by set. This is the example of set that stores value not entity reference that is why are going to use element instead of one-to-many. 1) create the Persistent classThis persistent class defines properties of the class including Set. 2) create the Mapping file for the persistent classHere, we have created the question.hbm.xml file for defining the list. 3) create the configuration fileThis file contains information about the database and mapping file. 4) Create the class to store the dataIn this class we are storing the data of the question class. How to fetch the data of SetHere, we have used HQL to fetch all the records of Question class including answers. In such case, it fetches the data from two tables that are functional dependent.
download this hibernate example (developed using MyEclipse IDE)
download this hibernate example (developed using Eclipse IDE)
Next TopicSet One To Many
|