Boulevard of Broken Builds

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.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...