相关辅助表上的 Hibernate MappingException
我有这样的情况:我想引用已更新任务对象的用户的名字和姓氏。这应该是一个直接的检索,但 Hibernate 并没有像我期望的那样连接关联。以下是对象定义:
Task Object:
@Entity
@Table(name = "TASKS")
public class TaskBean {
...
@ManyToOne(targetEntity = UserBean.class, optional=true)
@JoinColumn(name="MODIFIED_BY", referencedColumnName="EMPLOYEE_ID")
public User getUser()
...
User Object:
@Entity
@Table(name = "USER_")
@SecondaryTable(name="LOCAL_USER",
pkJoinColumns={
@PrimaryKeyJoinColumn(name="PORTAL_USER_ID", referencedColumnName="USERID")})
public class UserBean {
private BigDecimal userId; // USERID
private String firstName; // FIRSTNAME
private String lastName; // LASTNAME
private String employeeId; // EMPLOYEE_ID
....
@Column(name="EMPLOYEE_ID", table="LOCAL_USER", updatable=false, insertable=false)
public String getEmployeeId() {
return employeeId;
}
问题在于 TaskBean 上的 @ManyToOne 定义。当我尝试对 TaskBeans 运行单元测试时,出现以下异常:
org.hibernate.MappingException:无法在 org.hibernate.mapping.Table(USER_) 及其相关的超表和辅助表中找到逻辑名称为 EMPLOYEE_ID 的列
这对我来说没有意义,因为我已经明确定义了EMPLOYEE_ID字段在 UserBean 中。由于该字段来自辅助表,是否无法执行此操作?从错误消息来看,这听起来像是一件合理的事情。
有什么建议吗?
I have situation where I would like to reference the first and last name of the user who has updated a task object. This should be a straight forward retrieval but Hibernate is not wiring the associations like I expect. Here are the object definitions:
Task Object:
@Entity
@Table(name = "TASKS")
public class TaskBean {
...
@ManyToOne(targetEntity = UserBean.class, optional=true)
@JoinColumn(name="MODIFIED_BY", referencedColumnName="EMPLOYEE_ID")
public User getUser()
...
User Object:
@Entity
@Table(name = "USER_")
@SecondaryTable(name="LOCAL_USER",
pkJoinColumns={
@PrimaryKeyJoinColumn(name="PORTAL_USER_ID", referencedColumnName="USERID")})
public class UserBean {
private BigDecimal userId; // USERID
private String firstName; // FIRSTNAME
private String lastName; // LASTNAME
private String employeeId; // EMPLOYEE_ID
....
@Column(name="EMPLOYEE_ID", table="LOCAL_USER", updatable=false, insertable=false)
public String getEmployeeId() {
return employeeId;
}
The problem is with the @ManyToOne definition on TaskBean. When I try to run a unit test against TaskBeans I get the following exception:
org.hibernate.MappingException: Unable to find column with logical name: EMPLOYEE_ID in org.hibernate.mapping.Table(USER_) and its related supertables and secondary tables
This doesn't make sense to me as I've clearly defined the EMPLOYEE_ID field within UserBean. Is it not possible to do this since that field is coming from a secondary table? The error message makes it sound like this is a reasonable thing to do.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如 Hibernate bug https://hibernate.atlassian.net/browse/HHH-7713
您可以使用给定的重音来应用解决方法来识别您引用的ColumnName `
as described on Hibernate bug https://hibernate.atlassian.net/browse/HHH-7713
you can apply workaround using gave accents to identify your referencedColumnName `