One-to-one hibernate ing

Source: Internet
Author: User

One-to-one hibernate ing

One-to-one ing has two ing modes:

One-to-one relationship between users and ID card information

User:

 

Package cn. itcast. one2one; public class User {private int userId; // User idprivate String userName; // User name private IdCard idCard; // identity public int getUserId () {return userId ;} public void setUserId (int userId) {this. userId = userId;} public String getUserName () {return userName;} public void setUserName (String userName) {this. userName = userName;} public IdCard getIdCard () {return idCard;} public void setIdCard (IdCard idCard) {this. idCard = idCard ;}}
IdCard:

 

 

Package cn. itcast. one2one; public class IdCard {private int user_id; // private int cardNum; // ID card number private String place; // birthplace private User user User; public int getUser_id () {return user_id;} public void setUser_id (int user_id) {this. user_id = user_id;} public int getCardNum () {return cardNum;} public void setCardNum (int cardNum) {this. cardNum = cardNum;} public String getPlace () {return place;} public void setPlace (String place) {this. place = place;} public User getUser () {return user;} public void setUser (User user) {this. user = user ;}}

 

Method 1: User. hbm. xml file based on foreign key mode
 
 
  
   
    
   
   
   
   
  
 
IdCard. hbm. xml file
 
 
  
   
    
   
   
    
   
  
 

Method 2: based on the primary key mode User. hbm. xml (the same as that based on the foreign key mode)
 
 
  
   
    
   
   
   
   
  
 
IdCard. hbm. xml file
 
 
  
   
    
    
     User
    
   
   
   
   
   
  
 
 

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.