Set set mapping three elements (from JavaBean mapping to data ORM)
1, Collection table (foreign key table, child table) name
2., specify the collection table foreign key <key column= "" >
3. Other elements of the collection table <element type= "" column= "" >
<set name= "AddressSet" table= "User_addressset" order-by= "Address ASC" > <key column= "UserId" ></ key> <element type= "string" column= "Address" ></element>
Note that when you access the collection element, you want new
But this is a better notation.
private int id;private String name;//private set<string> addressset;//database does not save this private set<string> Addressset=new hashset<string> ();//recommended to write simplified code writing
public void Test () {Session session=sessionfactory.opensession (); Transaction tx=session.begintransaction (); User User=new user (); Set<string> set=new hashset<string> () set.add ("Bengbu");//objects in the object are Set.add ("Xuancheng") that need new, User.setname ("SS"); User.setaddressset (set); Session.save (user); Tx.commit (); Session.close ();}
Set Set mappings in Hibernate