gpt4 book ai didi

hibernate-mapping - 如何将与列相同的命名策略应用于@Index columnList?

转载 作者:行者123 更新时间:2023-12-05 05:13:43 25 4
gpt4 key购买 nike

由于 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;

...
}
数据库中名为 attached_by_id 的索引 columnList 中的

attachedBy_id 列。Hibernate 无法识别正确的物理列名称并抛出异常:

org.hibernate.AnnotationException: Unable to create unique key constraint (attachedBy_id) on table attachment: database column 'attachedBy_id' not found. Make sure that you use the correct column name which depends on the naming strategy in use (it may not be the same as the property name in the entity, especially for relational types)

我无法更改 JBPM 的代码。我也不想更改数据库中的列名(无论如何都无济于事),但我需要将 attachedBy_id 从 @Index columnList 映射到 attached_by_id某种程度上来说。是否可以对索引columnList应用同样的命名策略?

最佳答案

你需要使用@JoinColumn:

@ManyToOne
@JoinColumn(name = "attached_by_id")
private UserImpl attachedBy;

你还需要更新@Index:

@Index(name = "IDX_Attachment_Id", columnList="attached_by_id"

关于hibernate-mapping - 如何将与列相同的命名策略应用于@Index columnList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53193257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com