
Originally Posted by
wdorninger
Hi all,
I'm searching for a way to externalize queries and already found a few solutions however I'm not really happy with the solutions. I'm using hibernate and hibernate annotations. Currently i have parked the queries in the entity objects of my domain model as if hibernate scans the objects for queries it only picks up the queries from the files that contain entities. However I feel that the queries should be either stored in the Repository classes as thats the place where I use the queries or should be externalized at all as this would make it possible to modify the queries (at least parts of it - e.g. simple modifications in the where clause where there are no bind values required).
I have collected the following so far:
(1) As I'm using annotations I thougth it might be possible to externalize the strings used in the annotations but I guess this is not possible as the Strings used in the annotations (@NamedQuery) have to be available at compile time.
(2) I could put the queries into a package-info.java class and use the org.springframework.orm.hibernate3.annotation.Anno tationSessionFactoryBean to load the annotations however this only works with the hibernate @NamedQuery annotations and not with the JPA variation of this annotation
(3) I guess I could also use a mixture of annotations and hbm files and put the named queries in the HBM files and add hibernate.archive.autodetection with a value of "class,hbm" in persistence.xml
So my questions are...
(1) Where do you store usually your queries?
(2) Whats the best way to store them when using hiberante annotations and spring? (externalize completely, in the code as named queries, etc.)?
Thanks
Walter