【问题标题】:Are these @Table(uniqueConstraints) and @Table(indexes) annotations the same?这些 @Table(uniqueConstraints) 和 @Table(indexes) 注释是否相同?
【发布时间】:2017-06-26 22:09:13
【问题描述】:

在 JPA / Hibernate 中创建索引时,这些是否完全相同?

@Table (uniqueConstraints = @UniqueConstraint (columnNames = {"series", "date"}))

还有:

@Table (indexes = {@Index (name = "idx", columnList = "series, date", unique = true)})

如果不是,有什么区别?

【问题讨论】:

    标签: hibernate jpa hibernate-annotations database-indexes jpa-annotations


    【解决方案1】:

    @UniqueConstraint@Index 都只是模式生成工具的提示,它对方言/数据库敏感。您的具体示例可能会为大多数数据库提供程序生成相同的索引 ddl。两者之间的一般区别在于您可以在不强制唯一性的情况下对列进行索引。当然,如果您不使用 JPA/hibernate 模式生成来生成模式,那么两者都无关紧要。如果您通常需要对索引或架构进行更多控制,您可能需要考虑使用 liquibase 或 flywheel 等工具。

    【讨论】:

    • 我喜欢同时使用 JPA 注释和 liquibase 来仔细检查架构的正确性
    猜你喜欢
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 2016-09-02
    • 2012-05-18
    相关资源
    最近更新 更多