hibernate - 在 Grails/Gorm 中索引外键

标签 hibernate grails grails-orm

使用 Grails/Gorm,我可以通过执行以下操作来定义索引:

class Person {
    String firstName
    static mapping = {
        table 'people'
        id column: 'person_id'
        firstName column: 'First_Name', index: 'Name_Idx'
    }
}

但是,如果我使用连接表,如下所示:

class Employee {
    static hasMany = [projects: Project]

    static mapping = {
        projects joinTable: [name: 'EMP_PROJ',
                             column: 'PROJECT_ID',
                             key: 'EMPLOYEE_ID']
    }
}

如何配置它以便对连接表中的列建立索引?

谢谢

最佳答案

如果您使用 database migration plugin您可以使用 createIndex更改集以创建索引:

changeSet(author: "..", id: "..") {
  createIndex(indexName: "indexname", tableName: "yourtable", unique: "true") {
    column(name: "country_code")
  }
}

关于hibernate - 在 Grails/Gorm 中索引外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234536/

相关文章:

hibernate - 在没有 Hibernate 或 GORM 的情况下使用 Grails 域类

java - org.hibernate.HibernateException : Current transaction is not in progress after migrate to Hibernate 5

java - 如何修复 "Detached entity passed to persist"Spring Boot+Hibernate

java - 什么时候拥有 Hibernate 二级缓存的 CPU yield 超过初始命中

grails - 查找属性的类型,具有域类和属性路径

Grails - save() 在集成测试中因 MissingMethodExcepition 而失败

java - 持久化有序域对象

java - 是否可以在 Grails 中使用 Kotlin?

rest - 存在Content-Type:application/x-www-form-urlencoded header 时,Grails RestfulController不使用JSON进行响应

grails - 保存大型域对象树的提示