hibernate-mapping - 如何将与列相同的命名策略应用于@Index columnList?
问题描述
由于 JBPM 的较新版本之一添加了索引内部类:
@Entity
@Table(name="Attachment",
indexes = {@Index(name = "IDX_Attachment_Id",
columnList="attachedBy_id"),
@Index(name = "IDX_Attachment_DataId",
columnList="TaskData_Attachments_Id")})
@SequenceGenerator(name="attachmentIdSeq",
sequenceName="ATTACHMENT_ID_SEQ", allocationSize=1)
public class AttachmentImpl implements InternalAttachment {
...
@ManyToOne()
private UserImpl attachedBy;
...
}
attachBy_id列来自数据库中名为attach_by_id的索引 columnList 。Hibernate 无法识别正确的物理列名并抛出异常:
org.hibernate.AnnotationException:无法在表附件上创建唯一键约束(attachedBy_id):找不到数据库列“attachedBy_id”。确保使用正确的列名称,这取决于使用的命名策略(它可能与实体中的属性名称不同,尤其是关系类型)
我无法更改 JBPM 的代码。我也不想更改数据库中的列名(无论如何也无济于事),但我需要以某种方式将 @Index columnList中的 attachBy_id映射到attach_by_id。是否可以对索引 columnList 应用相同的命名策略?
解决方案
您需要使用@JoinColumn
:
@ManyToOne
@JoinColumn(name = "attached_by_id")
private UserImpl attachedBy;
您还需要更新@Index
:
@Index(name = "IDX_Attachment_Id", columnList="attached_by_id"
推荐阅读
- kubernetes - 如何让 SSH 在 Kubernetes 上运行?
- dpdk - DPDK是否支持slave启动一个新线程?
- go - TIMESCALEDB 架构问题
- node.js - NodeJS:无法扩展 Promise 对象:没有基本构造函数具有指定数量的类型参数
- rust - 尝试使用带有 glutin 事件循环关闭的 rodio 音频板条箱时出现问题
- android - SpannableStringBuilder 附加一个 SpannableString 对象不显示跨度?
- reactjs - 决定谁进入管理面板,谁不使用 React Admin
- redis - 在redis中存储嵌套对象层次结构
- python - 当我“pip install mmseg”时,出现错误“NameError: name 'reload' is not defined”
- python - 如何在 python 中直接将所有输出传输到 csv?