简体   繁体   中英

JPA orm.xml support for database index

I do not see any option to do something like, in orm.xml file, of JPA2 .

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

I see there is hbm.xml files, which offers that, but I wonder if JPA 2.0 really lacks this feature as part of the standard.

so I can avoid the transformation to hbm.xml files...

JPA 2.0 table XSD type looks like this:

<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>

While JPA 2.1 looks as follows:

<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>

So, you don't have the index attribute on the table type that's provided on a per-entity level:

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

However, you don't need to use hbm2ddl in your application. Just use Flyway instead and you are way better off .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM