码迷,mamicode.com
首页 > Web开发 > 详细

hibernate many2one

时间:2017-10-09 16:42:04      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:ack   imp   int   ble   generated   ``   private   com   public   

package com.bjsxt.hibernate;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name="t_user")
public class User {
@Id
@GeneratedValue
private int id;
private String name;
@ManyToOne
@JoinColumn(name ="groupId")          //多加了一列   表示 某个user 属于那个group          多对一  多的一方 加字段     
private Group group;
public int getId() {
return id;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}



}

 

``````````````````````````````````````````````````````````````````````

 

package com.bjsxt.hibernate;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name="t_group")
public class Group {
@Id
@GeneratedValue
private int id;
private String name;
public 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;
}


}

hibernate many2one

标签:ack   imp   int   ble   generated   ``   private   com   public   

原文地址:http://www.cnblogs.com/lize1215/p/7641508.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!