开发者

SQL\HQL queries repository

While working on some java projects i've saw some sort of SQL repository.

The idea was to place all queries in one(or few) xml files and retrieve them when needed by name. Something like this:

String sql = getSQLRepository().getSQL("SELECT_ALL_ROWS", params)
String sql2 = getSQLRepository().getSQL("SELECT_ROWS_WITH_COND", params)

In my current Grails project i have a lot of HQL queries in dozens of classes and it's hard to track them all. It seems that HQL repository would be very nice solution.

So could anyone tell if some sort of SQL\HQL repository implementation allready present or there are better so开发者_StackOverflow社区lutions present ?


Have a look at Mapping Queries in Hibernate reference.


After we started use the http://source.mysema.com/display/querydsl there is no need to think about text queries and how to manage them.


I'd recommend you to use the good old properties files. You can put them into your classpath and then use as following:

Properties sql = new Properties();
properties.load(getClass().getResourceAsStream("sql.properties"));
////////
String query = sql.get("SELECT_ALL_ROWS");


I'm sorry, and it doesn't relate to Hibernate, but when I worked with iBatis, - there are the situation as you are writing about exactly. A few xml (partially generated itself) files, containing SQL queries, which was easily to use in DAO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜