JPA2 JoinColumns JoinColumn 名称不受尊重。 (Hibernate 3.6 和 H2)

发布于 2024-12-11 06:58:52 字数 1399 浏览 0 评论 0原文

这是简化的代码片段,省略了 IdClass 详细信息。我遇到的问题是表定义是:

ClientPersonalityModel
(
 client_id int not null,
 personality_trait_id int not null,
 personality_type_id int not null,
 primary key (client_id, personality_trait_id, personality_type_id)
)

类是:

@Entity
public class ClientPersonalityModel
{
    @Id 
    @ManyToOne
    @JoinColumn(name="client_id")
    protected ClientModel client;

    @Id
    @ManyToOne
    @JoinColumns({
        @JoinColumn(name="personality_trait_id",referencedColumnName="id"),
        @JoinColumn(name="personality_type_id",referencedColumnName="personality_type_id")
    })
    protected ClientPersonalityTraitModel trait;
}

但持久性框架正在尝试使用列 CLIENT_ID、TRAIT_ID、TRAIT_PERSONALITY_TYPE_ID。

为什么 @JoinColumn 名称被忽略?

它抛出一个异常:

初始sessionFactory创建失败.org.hibernate.MappingException:无法从表client_personalities中的物理名称personality_type_id中找到逻辑列名称

java.lang.ExceptionInInitializerError 引起原因: org.hibernate.MappingException:无法从表 client_personalities 中的物理名称 individual_type_id 找到逻辑列名称

许多示例中都介绍了这种情况,但没有覆盖列名称。

例如:

清单 10-12。具有 Pro JPA 2 中的从属标识符的项目

@Entity
@IdClass(ProjectId.class)
public class Project {
    @Id private String name;
    @Id
    @ManyToOne
    private Department dept;
    // ...
}

(ISBN 978-1-4302-1956-9 / 978-1-4302-1957-6)

Here is the reduced snippet, omitting the IdClass details. The issue I am having is the tables definition is:

ClientPersonalityModel
(
 client_id int not null,
 personality_trait_id int not null,
 personality_type_id int not null,
 primary key (client_id, personality_trait_id, personality_type_id)
)

And the class is:

@Entity
public class ClientPersonalityModel
{
    @Id 
    @ManyToOne
    @JoinColumn(name="client_id")
    protected ClientModel client;

    @Id
    @ManyToOne
    @JoinColumns({
        @JoinColumn(name="personality_trait_id",referencedColumnName="id"),
        @JoinColumn(name="personality_type_id",referencedColumnName="personality_type_id")
    })
    protected ClientPersonalityTraitModel trait;
}

But the persistence framework is trying to use columns CLIENT_ID, TRAIT_ID, TRAIT_PERSONALITY_TYPE_ID.

Why are the @JoinColumn names being ignored?

It throws an exception:

Initial sessionFactory creationfailed.org.hibernate.MappingException: Unable to find logical column name from physical name personality_type_id in table client_personalities

java.lang.ExceptionInInitializerError
Caused by: org.hibernate.MappingException: Unable to find logical column name from physical name personality_type_id in table client_personalities

This case is covered in many examples, but without overriding the column names.

Ex:

Listing 10-12. Project with Dependent Identifier

@Entity
@IdClass(ProjectId.class)
public class Project {
    @Id private String name;
    @Id
    @ManyToOne
    private Department dept;
    // ...
}

from Pro JPA 2 (ISBNs 978-1-4302-1956-9 / 978-1-4302-1957-6)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木森分化 2024-12-18 06:58:52

也许尝试分别切换到@PrimaryKeyJoinColumns/@PrimaryKeyJoinColumn

它有助于 这个案例,我相信可能也是同样的原因。

Perhaps try switching to @PrimaryKeyJoinColumns/@PrimaryKeyJoinColumn, respectively.

It helped in this case, I believe it might be the same reason.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文