Archive for July, 2006
Extending org.hibernate.Dialect
by on Jul.21, 2006, under Uncategorized
Today I ran into the problem that hibernate does not support all SQL functions some databases might support. Although the solution wasn’t hard to find, it wasn’t the way I would have come up with. Apparently Hibernate does not want to support everything in their dialects. Even though they are database specific. So the easiest way to solve my problem was to extend the dialect I was using.
class HibernateMySqlDialect extends MySQLInnoDBDialect {
public HibernateMySqlDialect() {
registerFunction("date_add_interval",
new SQLFunctionTemplate(Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)"));
registerFunction("date_format",
new SQLFunctionTemplate(Hibernate.DATE, "date_format(?1, ?2)"));
}
}
That’s all what’s necessary to start using these SQL functions in your HQL queries.