One of hibernate

Source: Internet
Author: User

One of hibernate

Annotation Version:

Group class:

 

Package com. hibernate. model; import java. util. hashSet; import java. util. set; import javax. persistence. entity; import javax. persistence. generatedValue; import javax. persistence. id; import javax. persistence. joinColumn; import javax. persistence. onetovel; import javax. persistence. oneToOne; import javax. persistence. table; @ Entity @ Table (name = _ Group) public class Group {private int id; private String name; private Set
 
  
Users = new HashSet
  
   
(); @ Id @ GeneratedValuepublic int getId () {return id;} public void setId (int id) {this. id = id;} public String getName () {return name;} @ onetoworkflow (mappedBy = group) // mappedBy must be written in both directions, and for database considerations, the association relationship should be designed on multiple sides, so mappedBypublic Set must be Set on onetoworkflow.
   
    
GetUsers () {return users;} public void setUsers (Set
    
     
Users) {this. users = users;} public void setName (String name) {this. name = name ;}}
    
   
  
 
User class:

 

 

package com.hibernate.model;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.Id;import javax.persistence.ManyToOne;import javax.persistence.Table;@Entity@Table(name=_User)public class User {private int id;private String name;private Group group;@ManyToOnepublic Group getGroup() {return group;}public void setGroup(Group group) {this.group = group;}@Id@GeneratedValuepublic int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}}
For configuration files and test cases, refer to previous articles.

 

 

Xml version:

Group class. The User class is the same as above.

User. hbm. xml:

 

 
     
      
       
        
    
       
       
       
  
 
Group. hbm. xml:

 

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.