I am building an application using annotations and MySql as the database. As part of the testing for many classes I need to get the current time, but I'd like to write that query only once. Additionally, I have to supply MySql queries to drop, create, and populate tables. But none of them will work with other databases.
It strikes me as desirable to move all of this redundant or vendor specific SQL into some central location either in a single Java file or in a single Hibernate configuration file, so that I can switch databases, and use another vendor-specific version of this central file.
Hibernate provides some capability to define queries in a mapping file, but I am currently using only hibernate.cfg.xml with only the session-factory defined, and there does not seem to be any place to centrally define these queries in this file.
What would you recommend, a java file, Hibernate configuration file(s), or some other strategy?
|