JPA2 JoinColumns JoinColumn 名称不受尊重。 (Hibernate 3.6 和 H2)
这是简化的代码片段,省略了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许尝试分别切换到
@PrimaryKeyJoinColumns/@PrimaryKeyJoinColumn
。它有助于 这个案例,我相信可能也是同样的原因。
Perhaps try switching to
@PrimaryKeyJoinColumns/@PrimaryKeyJoinColumn
, respectively.It helped in this case, I believe it might be the same reason.