我正在尝试将数据插入表中。我收到错误
31456 [http-bio-8080-exec-7] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
31457 [http-bio-8080-exec-7] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.analytica.pojo.Client_Unit
31457 [http-bio-8080-exec-7] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.analytica.pojo.Client_Unit on table cu_client_unit
@OneToOne or @ManyToOne on com.analytica.pojo.Client_Unit.city_id references an unknown entity: com.analytica.pojo.CityMaster
error
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.analytica.pojo.Client_Unit.city_id references an unknown entity: com.analytica.pojo.CityMaster
Unit
@ManyToOne
@JoinColumn(name="CU_CM_ID")
public CityMaster getCity_id() {
return city_id;
}
public void setCity_id(CityMaster city_id) {
this.city_id = city_id;
}
City
@Id
@Column(name="CM_ID")
@OneToMany
public int getCity_id() {
return city_id;
}
public void setCity_id(int city_id) {
this.city_id = city_id;
}
我正在尝试将值插入db。我在com.analytica.pojo.Client_Unit.city_id引用一个未知实体时收到@OneToOne或@ManyToOne错误:com.analytica.pojo.CityMaster 错误
答案 0 :(得分:0)
在单向OneToMany场景中,您只需要注释父类。
@Entity
public class Unit{
@Id
@GeneratedValue
private int id;
//getter and setter
}
@Entity
public class CityMaster{
@Id
@GeneratedValue
private int id;
@OneToMany
@JoinColumn(name = "CU_ID")
Set<Unit> units = new Hashmap<>();
//getter and setter
}