2 回答
TA贡献1770条经验 获得超3个赞
看看这个:stackoverflow
不同的
JPA
版本,用法略有区别。因为你也没说你是什么版本,只能给出原帖,自己对照了
还有,你的Index
类,引入对了么?import javax.persistence.Index;
TA贡献1808条经验 获得超4个赞
亲,你要去看看 @Index 的定义及其使用。请参考下面的例子吧:
import java.util.*
import javax.persistence.*
@Entity
@Table(indexes = arrayOf(
Index(name = "idx_url", unique = true, columnList = "url"),
Index(name = "idx_category", unique = false, columnList = "category")))
class Image {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long = -1
@Version
var version: Int = 0
var category: String = ""
var isFavorite: Int = 0
var url: String = ""
var gmtCreated: Date = Date()
var gmtModified: Date = Date()
var isDeleted: Int = 0 //1 Yes 0 No
var deletedDate: Date = Date()
override fun toString(): String {
return "Image(id=$id, version=$version, category='$category', isFavorite=$isFavorite, url='$url', gmtCreated=$gmtCreated, gmtModified=$gmtModified, isDeleted=$isDeleted, deletedDate=$deletedDate)"
}
}
添加回答
举报