Reputation: 1324
I have two tables vehicleregister
and groupdetails
for that I have beans as VehicleRegisterBean
and GroupDetails
common field is groupid
. Here 1 group can contains many vehicles for that I am performing OnetoMany relation for that I have defined bean as,
VehicleRegiserBean ,
@Entity
@Table(name = "vehicle_register")
public class VehicleRegisterBean {
// somefields
@ManyToOne
@JoinColumn(name="groupid", nullable=false)
private GroupDetails groupDetails;
//getter setters
}
and
GroupDetails,
@Entity
@Table(name = "group_details")
public class GroupDetails {
//some fields
@OneToMany(mappedBy="GroupDetails")
private Set<VehicleRegisterBean> vehicleRegisterBean;
//getters setters
}
but I am getting exception as,
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)
can anyone help me to solve this.
Upvotes: 0
Views: 514
Reputation: 21393
The value for mappedBy
attribute represents the field in your VehicleRegisterBean
class which is groupDetails
but you are using GroupDetails
in mappedBy
.
So hibernate is trying to look for property GroupDetails
in VehicleRegisterBean
and saying that it is not able to find that property. Thats is what the error says:
mappedBy reference an unknown target entity property:
com.abc.its.beans.VehicleRegisterBean.GroupDetails
Upvotes: 2
Reputation: 2491
change
@OneToMany(mappedBy="GroupDetails")
to
@OneToMany(mappedBy="groupDetails")
it is the name that you declare here,
private GroupDetails groupDetails;
Upvotes: 2