I use Hibernate and widely adopted Hibernate Query Language to define queries in my DAOs.
Anyway sometimes HQL isn't capable of performing specific task compared to native SQL query.
For example the following Postgres expression is not "convertible" to HQL:
my_date > current_date - interval '10 year'
This means that in some case I'm writing native queries. Considering that I'm using another database for integration testing (http://hsqldb.org/) which doesn't reflect the syntax of the Postgres expression above. This results in test exception during DAO methods using such native query.
How do you handle such cases? I can just think of following scenarios:
- Never use native query and try to build everything in HQL (possible?)
- Don't test methods which use such queries (unhappy)
- Use same database both for production and development (performance problem)
Other, more interesting solution? Thanks