
- java.util.List
- java.util.Set
- java.util.SortedSet
- java.util.Map
- java.util.SortedMap
- java.util.Collection
- or write the implementation of org.hibernate.usertype.UserCollectionType
JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=UbpbqqIw_3Q&t=1725s[/embed]Mapping collection in mapping file:
There are numerous subelements of ,
Understanding key element:
The key component is utilized to characterize the outside key in the joined table in light of the first personality. The remote key component is nullable as a matter of course. So for non-nullable remote key, we have to determine not-invalid property, for example.
- indexed
- non-indexed
Collection Elements:
- element
- component-element
- one-to-many, or
- many-to-many
Mapping List in Collection:
In the event that our steady class has List question, we can outline List effectively either by component of class in mapping document or by comment.
Here, we are utilizing the situation of Forum where one inquiry has numerous answers.<class name="com.javaspot.Question" table="q100">
On the persistent class off chance that the industrious class has list question that contains the substance reference, we have to utilize one-to-numerous relationship to outline list component.Here, we are utilizing the situation of Forum where one inquiry has numerous answers.
package com.javaspot;import java.util.List;public class Question {private int id;private String qname;private ListHere, we have utilized HQL to get every one of the records of Question class including answers. In such case, it gets the information from two tables that are utilitarian ward. Here, we are immediate printing the question of answer class, yet we have superseded the toString() technique in the Answer class returning answer name and blurb name. So it prints the appropriate response name and poster name as opposed to reference id.
FetchData.java:
package com.javaspot;import java.util.*;import org.hibernate.*;import org.hibernate.cfg.*;public class FetchData {public static void main(String[] args) {Session session=new Configuration().configure("hibernate.cfg.xml").buildSessionFactory().openSession();Query query=session.createQuery("from Question");ListIn the event that our persistent class has Set protest, we can outline Set by set component in the mapping document. The set component doesn't require list component. The one contrast amongst List and Set is that, it stores just extraordinary esteems.
<class name="com.javatpoint.Question" table="q102">...In the event that the steady class has set question that contains the element reference, we have to utilize one-to-numerous relationship to outline set component. We can delineate rundown question by either set. It is non-file based and won't permit copy components.
Mapping Map in collection mapping using xml file:Hibernate enables you to Map elements with the RDBMS. As we probably am aware, rundown and Map are record based collection. If there should be an occurrence of Map, list section functions as the key and component segment acts as the esteem.
Many to Many Mapping:We can delineate to numerous connection either utilizing set, pack, outline. Here, we will utilize delineate many-to-many mapping. In such case, three tables will be made. Bidirectional Association:Bidirectional association enables us to bring points of interest of ward question from both side. In such case, we have the reference of two classes in each other.We should take a case of Employee and Address, if Employee class has-a reference of Address and Address has a reference of Employee. Moreover, you have connected coordinated or one-to-numerous relationship for the classes in mapping document too, it is known as bidirectional association.
Lazy CollectionLazy collection stacks the kid protests on request, it is utilized to enhance execution. Since Hibernate 3.0, apathetic accumulation is empowered of course.To utilize lazy collection, you may alternatively utilize lazy="true" trait in your gathering. It is as a matter of course genuine, so you don't have. On the off chance that you set it to false, all the kid items will be stacked at first which will diminish execution if there should be an occurrence of enormous information.