询问休眠:错误:mappedBy 引用未知的目标实体属性
Posted
技术标签:
【中文标题】询问休眠:错误:mappedBy 引用未知的目标实体属性【英文标题】:ASK HIBERNATE: ERROR: mappedBy reference an unknown target entity property 【发布时间】:2014-12-26 22:37:02 【问题描述】:这是我的 sql
CREATE TABLE room
(
room_id INT,
primary key (room_id)
) ENGINE=InnoDB;
CREATE TABLE people
(
people_id INT,
live_in INT,
primary key (people_id),
foreign key (live_in) references room(room_id)
) ENGINE=InnoDB;
这是我的第二个实体
@Entity
@Table(name="room")
public class RoomClass
private int RoomIdMember;
private Set<PeopleClass> Peoples = new HashSet<PeopleClass>(0);
@Id
@Column(name="room_id")
public int getRoomIdMember()
return RoomIdMember;
public void setRoomIdMember(int roomIdMember)
RoomIdMember = roomIdMember;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "LiveInMem")
public Set<PeopleClass> getPeoples()
return Peoples;
public void setPeoples(Set<PeopleClass> peoples)
Peoples = peoples;
@Entity
@Table(name="people")
public class PeopleClass
private int PeopleIdMem;
private RoomClass LiveInMem;
@Id
@Column(name="people_id")
public int getPeopleIdMem()
return PeopleIdMem;
public void setPeopleIdMem(int peopleIdMem)
PeopleIdMem = peopleIdMem;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
//@ManyToOne
@JoinColumn(name="live_in", referencedColumnName="room_id")
public RoomClass getLiveInMem()
return LiveInMem;
public void setLiveInMem(RoomClass liveInMem)
LiveInMem = liveInMem;
在主函数中,当我写的时候
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
...
Eclipse 说
mappedBy reference an unknown target entity property: quang.entity.PeopleClass.LiveInMem in quang.entity.RoomClass.peoples
为什么会出现这个错误?
【问题讨论】:
尝试使用小写的peoples
作为变量名
哦,它工作,:) 非常感谢你
【参考方案1】:
尝试将Peoples
和所有其他类变量设为小写。
这是通常/标准的Java
代码约定。
我不确定,但我强烈怀疑这与您的问题有关。
【讨论】:
以上是关于询问休眠:错误:mappedBy 引用未知的目标实体属性的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.ExceptionInInitializerError 和 org.hibernate.AnnotationException: mappedBy 引用了一个未知的目标实体属性:
双向休眠 - org.hibernate.AnnotationException: Unknown mappedBy in: error