我正在嘗試使用@Index注釋在外鍵上創建索引。不幸的是,編譯器抱怨以下訊息:
This annotation is not applicable to target 'member property with backing field'
我在這里做錯了什么?
@Entity
@Table(name = "my_entity")
class MyEntity(someValue: Long) : BaseEntity(someValue) {
// .. some fields
@OneToOne
@JoinColumn(name = "another_entity")
@Index(name = "ix_another_entity")
var anotherEntity: AnotherEntity? = null
}
uj5u.com熱心網友回復:
不能像這樣@Index使用(在 java 和 kotlin 中都沒有),而是可以將它用作@Table注釋的一部分:
@Table(name= "my_entity", indexes = [ Index(columnList = "another_entity") ])
使用 JPA 指定索引(非唯一鍵)
(注意,例如 MySQL 自動為外鍵創建索引:Does MySQL index foreign key columns automatically?)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/424561.html
上一篇:將ModelMapper映射從物體類添加到具有OneToMany關系的Dto類
下一篇:java中實體變數的使用
