Adding database indexes with Hibernate

I recently had to add additional indexes to some tables in a MySQL database that were setup with Hibernate.

A simple task… in the mapping hbm.xml just specify the index on the property by adding:


index="some_index_name"

Except it didn’t work. Even dropping the tables and letting Hibernate re-create them from scratch with the updated mappings didn’t work. As it turns out, there is a bug in the implementation of Hibernate with MySQL that doesn’t create the indexes.

The workaround is to setup a database-object block in your Hibernate mapping file with the SQL you need:

<hibernate-mapping>
<database-object>
<create>
CREATE INDEX my_index ON my_table (column_name)
</create>
<drop></drop>
</database-object>
</hibernate-mapping>

You can also specify which dialects you want this targetted at as well:

<hibernate-mapping>
<database-object>
<create>
CREATE INDEX my_index ON my_table (column_name)
</create>
<drop></drop>
<dialect-scope name=”org.hibernate.dialect.Oracle9Dialect”/>
<dialect-scope name=”org.hibernate.dialect.OracleDialect”/>
</database-object>
</hibernate-mapping>

Hopefully this will save someone some time!

References:

I’m a Sakai Fellow!

I recently found out that I have been selected as a Sakai Fellow for the upcoming year!

“The Sakai Fellows program seeks to foster community leadership and contribution through recognizing and supporting active contributors. Contributors bring varied expertise to the community, including architecture, design and development of technology, best practices in teaching, learning, research and collaboration, and coordination of community functions.

The purpose of the Sakai Foundation Fellows Program is to enable outstanding Sakai volunteer contributors and/or evangelists to continue and extend their involvement in Sakai, by providing material resources to support their work.”

This is really awesome news, twofold in that it is great to be recognised for my contributions to the Sakai community and also because I can set myself some challenges for some really interesting development work over the coming year.
Here’s a rough list on what I’d like to accomplish in my Fellowship:

  • Continue developing and enhancing Profile2, the Web 2.0 profile/social networking app for Sakai 2.
  • Put Profile2 through its paces for promotion to core for Sakai 2.7.
  • Enhance Profile2 into a multi-institution cross-search social-matching tool as part of a JISC project we are undertaking at Lancaster University.
  • Rally to get my TinyUrlService into Sakai2/K1.
  • Develop a similar TinyUrlService for Sakai3/K2.
  • Improve the current web service support in Sakai2.
  • Get web service support into Sakai3/K2.
  • Get involved with the development of the Admin tools in Sakai3. I’ve been involved in integration and administration of Sakai for years. I’ve written two remote administration apps for Sakai, one publicly available as SakaiAdminX (the X is for external). I know what works and what’s too complicated for users.
  • Continued presence on the mailing lists. There’s been a recent influx of new users getting into development, I’ll try to nurture and guide them on the Sakai development path.
  • Contribute to the Sakai Developer Bootcamps, starting with the Boston conference in July.
  • Continue to write articles about various aspects of Sakai and post them on my Confluence space, blog about them here, or both. All to raise awareness and understanding about Sakai.
  • Continue my branch management duties for 2.4.x and 2.5.x
  • Get behind Sakai 2.7 and make it the best Sakai 2.x release yet, feature packed and issue free!
  • Do all of that whilst managing our firstborn due in a few months!

So thanks to my nominator(s) and for those on the committee who selected me. And congratulations to my Sakai Fellow colleagues!

Exciting times ahead!