Hibernate - 以列名称为前缀的变量名称

时间:2013-09-30 08:47:36

标签: java hibernate hibernate-mapping hibernate-criteria hibernate-annotations

我有以下两个班级

@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的新手。

0 个答案:

没有答案