【问题标题】:JPA orm.xml support for database indexJPA orm.xml 对数据库索引的支持
【发布时间】:2017-06-24 12:27:16
【问题描述】:

orm.xml 文件中,我没有看到任何选项可以执行 JPA2 之类的操作。

<basic name="developer">
    <index />
    <column name="developer"/>
</basic>

我看到有 hbm.xml 文件提供了该功能,但我想知道 JPA 2.0 是否真的缺少此功能作为标准的一部分。

这样我就可以避免转换为 hbm.xml 文件...

【问题讨论】:

    标签: java xml hibernate jpa orm


    【解决方案1】:

    JPA 2.0 table XSD 类型如下所示:

    <xsd:complexType name="table">
        <xsd:sequence>
            <xsd:element name="unique-constraint" type="orm:unique-constraint" 
                       minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="name" type="xsd:string"/>
        <xsd:attribute name="catalog" type="xsd:string"/>
        <xsd:attribute name="schema" type="xsd:string"/>
    </xsd:complexType>
    

    而 JPA 2.1 如下所示:

    <xsd:complexType name="table">
        <xsd:sequence>
          <xsd:element name="unique-constraint" type="orm:unique-constraint" 
                       minOccurs="0" maxOccurs="unbounded"/>
          <xsd:element name="index" type="orm:index" 
                       minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="name" type="xsd:string"/>
        <xsd:attribute name="catalog" type="xsd:string"/>
        <xsd:attribute name="schema" type="xsd:string"/>
    </xsd:complexType>
    

    因此,您没有在每个实体级别提供的 table 类型上的 index 属性:

    <entity class="Post" access="FIELD">
        <table>
            <index column-list="first_name,last_name" name="name_idx" unique="true"/>
        </table>
        <attributes>
            ...
        </attributes>
    </entity>
    

    但是,您不需要在应用程序中使用 hbm2ddl。只需use Flyway instead and you are way better off

    【讨论】:

      猜你喜欢
      • 2011-07-06
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多