我有两个表vehicleregister
和groupdetails
,因为我有VehicleRegisterBean
的bean,GroupDetails
公共字段是groupid
。这里有1组可以包含许多工具,我正在执行OnetoMany关系,因为我将bean定义为,
VehicleRegiserBean,
@Entity
@Table(name = "vehicle_register")
public class VehicleRegisterBean {
// somefields
@ManyToOne
@JoinColumn(name="groupid", nullable=false)
private GroupDetails groupDetails;
//getter setters
}
和
GroupDetails,
@Entity
@Table(name = "group_details")
public class GroupDetails {
//some fields
@OneToMany(mappedBy="GroupDetails")
private Set<VehicleRegisterBean> vehicleRegisterBean;
//getters setters
}
但我得到例外,
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.abc.its.beans.VehicleRegisterBean.GroupDetails in com.abc.its.beans.GroupDetails.vehicleRegisterBean
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:685)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:645)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
任何人都可以帮我解决这个问题。
答案 0 :(得分:3)
mappedBy
属性的值代表VehicleRegisterBean
类中groupDetails
的字段,但您在GroupDetails
中使用mappedBy
。
因此,hibernate试图在GroupDetails
中查找属性VehicleRegisterBean
,并说它无法找到该属性。这就是错误所说的:
mappedBy reference an unknown target entity property:
com.abc.its.beans.VehicleRegisterBean.GroupDetails
答案 1 :(得分:2)
变化
@OneToMany(mappedBy="GroupDetails")
到
@OneToMany(mappedBy="groupDetails")
这是您在此声明的名称,
private GroupDetails groupDetails;