我有以下两个班级
@Entity
Class AAA {
@EmbeddedId
private AAA_ID aaa_id;
private String field1;
private String field2;
@ManyToOne
private BBB bbb;
}
@Embeddable
class AAA_ID {
@Column(name="id1")
private String id1;
@Column(name="id2")
private String id2;
}
@Entity
Class BBB {
@EmbeddedId
private BBB_ID bbb_id;
private String field3;
private String field4;
@OneToMany(mappedBy = "bbb")
@JoinColumns({
@JoinColumn(name = "id1", referencedColumnName = "id1"),
@JoinColumn(name = "id2", referencedColumnName = "id2")})
private List<AAA> aaaList=new ArrayList<AAA>();
}
@Embeddable
class BBB_ID {
@Column(name="id1")
private String id1;
@Column(name="id2")
private String id2;
@Column(name="id3")
private String id3;
@Column(name="id4")
private String id4;
}
然后我这样编码:
Root<AAA> AAARoot = criteriaQuery.from(AAA.class);
Join<AAA, BBB> customerContactPath = AAARoot.join("bbb");
criteriaQuery.select(AAARoot);
List<AAA> AAAList = getEntityManager().
createQuery(criteriaQuery).getResultList();
它给我以下例外
1869947 [8206263@qtp-21049255-16]
ERROR org.hibernate.util.JDBCExceptionReporter - line 1,
Table 'AAA' owned by 'ingres' does not contain column 'bbb_id1'.
正如您所看到的,变量名称bbb
被添加到列id1
的前缀,这就是上述异常即将发生的原因。
P.S。我是hibernate的新手。