Hi,
I have a schema which would benefit from multi-column indexes. The table in question has fields like user_id, lastName, firstName, etc.
I offer the user the ability to filter his contacts using any of lastName, firstName, etc. All searches are related to the specific user doing the search.
My .hbm.xml file looks like this:
Code:
<class name="Contact" proxy="Contact" table="contacts">
<id name="id" column="contact_id" type="long">
<generator class="native"/>
</id>
<component name="name" class="Name">
<property name="lastName" column="lastname" type="string" length="40"/>
<property name="firstName" column="firstname" type="string" length="40"/>
<property name="middleInitial" column="middleinitial" type="string" length="4"/>
</component>
<property name="firm" column="firm" type="string" length="80"/>
<many-to-one name="user" column="user_id" not-null="true"/>
</class>
<query name="contacts.filteredByName"><![CDATA[
from Contact c
where c.user.id = :user_id
and (lower(c.name.lastName) like lower(:startsWith)
or lower(c.name.firstName) like lower(:startsWith)
or lower(c.firm) like lower(:startsWith))
order by c.name.lastName asc, c.name.firstName asc, c.firm asc
]]></query>
The indexes I would like to create would be on user_id + lastName, user_id + firstName, etc.
Is there a way to specify such multi-column indexes in my mappings file, such that the hbm2ddl generator will pick these up and generate the appropriate SQL statements ?
I can always create the indexes manually, but I thought it would be nice if I could do it once and for all in my mapping file.
I am using Hibernate 2.1.1 on JDK 1.4.2 with MySQL 3.23 as the back-end, on Tomcat 4.1.28.
I searched the web using Google, and the Hibernate forums, and the only items returned are concerning Map mappings with multi-column indexes.
Thanks !
Fran