Hello, We've create a query repository that stores all of our entity queries in a table. We previously where using named queries in our entities with the @NamedQuery. We liked this model for our simple applications and simple queries but did not feel confident with storing more complex and security driven queries in code or xml. Furthermore we are attempting to have ALL sql in one location for ALL applications so that its not spread acrossed a verity of locations. With that brief explanation of our architecture and what we are trying to do, hopefully that will subside any arguments to our model in advance. My basic question is, can i leverage the benefit of named queries without actual using them? Is there a way to pre-compile a query and store it much like a named query, so its not checked every time a query is ran? Also just an FYI, our query repository holds things like... -What application the query belongs to -What syntax the query is in (JPA/EJBQL, HQL, T-SQL, ETC.) -The query -The return type of the query (com.mystuff.MyObject) -Any parameters the query takes -Any query hints and their value (org.hibernate.readOnly) The biggest benefit of the type of model is that a we can change the business logic of a query at runtime just by updating our query table. I've implemented our own caching system so that anytime anything changes in the table all queries get re-load back into our repository with there updates. This is very nice because we can add hints, order by's, change logic or whatever on the fly. It also lets the DBA have control over the queries without looking at Java code. Thanks in advance!
Did you ever find a solution to this?
I'm after the same functionality (but for different reasons); I have queries that are mostly static, but may require a "select count" version of themselves, or a user-affected ordering clause...
I want to "pre-compile" a version with the default ordering and a count and then dynamically build the rest -- but that would require the same query text 3 times (not very DRY)