1

我有以下 2 节课

@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这就是上述异常出现的原因。

PS我是新来的冬眠。

4

0 回答 0