Requirements for persistence classes: 1 ). there is a default constructor; 2 ). all attributes have the setter and getter Methods 3 ). there is an object identifier Oid; 4 ). if a Set attribute exists, the interface type must be defined as List, Set, and Map. It cannot be defined as HashSet, hashMap, ArrayList, etc. 1. Hibernate advanced <ing <set> element: You can map the attributes of the java. util. Set interface. The elements are unordered and cannot be repeated. <List> element: You can map the attributes of the java. util. List interface in order. You need to store the location of each element with an additional index in the table corresponding to the set attribute. <Bag> <idbag> element: You can map the attributes of the java. util. Collection interface. The elements can be repeated, but the sequence is not saved. <Map> element: You can Map the attributes of the java. util. map interface. The elements are saved as key/value pairs, which are also unordered. <Primitive-array> <array>: maps array elements. 2. the main code of these advanced mappings <set> element private Set <String> hobbies; <set name = "hobbies" table = "student_holobby"> <key column = "student_id"/> <element type = "string" column = "hobby_name" not-null = "true ""/> </set> note the following: the set tag mentioned here is different from the set tag in the previously described link ing. I don't know if it is noticed. Here there is an element tag but there is no link type tag; the attribute not-null = "true" of the element label indicates that the field is not allowed to be empty. <list> element private List <String> hobbies; <list name = "hobbies" table = "student_holobby"> <key colum N = "student_id"/> <list-index column = "posistion"/> <element type = "string" column = "hobby_name" not-null = "true"/> </list> note the following: the list tag and the set tag ing file are written in the same way. The difference is that the list tag has the list-index tag, this label is used to add an index location to the table. Why is there one more !? In fact, it is determined by the difference between list and set, li. St is ordered, so there must be an index location to uniquely identify, but set does not. <Bag> element private Collection <String> hobbies; <bag name = "hobbies" table = "student_holobby"> <key column = "student_id"/> <element type = "string" column = "hobby_name" not-null = "true ""/> </bag> note the following: the role of the bag tag is to achieve the same functions as the list tag, but there is no additional identifier for the index location. The property type in the persistence class corresponding to the bag tag is the Collection set type, that is, the parent interface of set and list. The former can achieve the functions achieved by the latter. The main function of bag is to make the data in order, but do not want the field of the generated ID location. <Map> element private Map <Long String> hobbies; <map name = "hobbies" table = "student_holobby"> <key column = "student_id"> <map-key column = "hobby_id" type = "long"/> <element type = "string" column = "hobby_name" not-null = "true"/> </map> 3. case analysis is based on xxx. hbm. some of the xml code is also the core code. The test code is listed below. SetTest. java package com. hbsi. set; import java. util. hashSet; import java. util. set; import org. hibernate. session; import org. junit. test; import com. hbsi. utils. hibernateSessionFactory; public class SetTest {@ Test public void add () {Session session = HibernateSessionFactory. getSession (); session. beginTransaction (); Person p = new Person (); p. setName ("keven"); Set <String> hobbies = new HashSet <String> (); hobbies. add ("sing"); hobbies. add ("dance"); p. setHobbies (hobbies); session. save (p); session. getTransaction (). commit (); HibernateSessionFactory. closeSession () ;}} ListTest. java package com. hbsi. list; import java. util. arrayList; import java. util. list; import org. hibernate. session; import org. junit. test; import com. hbsi. utils. hibernateSessionFactory; public class ListTest {@ Test public void add () {Session session = HibernateSessionFactory. getSession (); session. beginTransaction (); Person p = new Person (); p. setName ("join"); List <String> hobbies = new ArrayList <String> (); hobbies. add ("backetball"); hobbies. add ("football"); p. setHobbies (hobbies); session. save (p); session. getTransaction (). commit (); HibernateSessionFactory. closeSession () ;}} BagTest. java package com. hbsi. bag; import java. util. arrayList; import java. util. list; import org. hibernate. session; import org. junit. test; import com. hbsi. utils. hibernateSessionFactory; public class BagTest {@ Test public void add () {Session session = HibernateSessionFactory. getSession (); session. beginTransaction (); Person p = new Person (); p. setName ("keven"); List <String> hobbies = new ArrayList <String> (); hobbies. add ("sing"); hobbies. add ("dance"); p. setHobbies (hobbies); session. save (p); session. getTransaction (). commit (); HibernateSessionFactory. closeSession () ;}} MapTest. java package com. hbsi. map; import java. util. hashMap; import java. util. map; import org. hibernate. session; import org. junit. test; import com. hbsi. utils. hibernateSessionFactory; public class MapTest {@ Test public void add () {Session session = HibernateSessionFactory. getSession (); session. beginTransaction (); Person p = new Person (); p. setName ("keven"); Map <Integer, String> hobbies = new HashMap <Integer, String> (); hobbies. put (1, "sing"); hobbies. put (2, "dance"); p. setHobbies (hobbies); session. save (p); session. getTransaction (). commit (); HibernateSessionFactory. closeSession ();}}