tags:

views:

13

answers:

1

Hi! I would like to include all named queries in a separate XML file and use it in persistence. How can I accomplish the same?

I am using Toplink JPA in a JSF-Web application. Actually I am not able to get the directory/file structure to use.

I tried to use in persistence.xml and tried to place the query file in several locations. Every time I am getting exception.

Please Help!!!

A: 

You can either place to XML file queries that later will be executed by

 EntityManager.createQuey(query)

where query is provided by XML.

Or, the better way(!), use already existing possibility to declare JPA parts in mapping XML (example see http://stackoverflow.com/questions/2373369/define-named-query-in-orm-xml-with-jpa-and-hibernate). In the last case you can even use:

 EntityManager.createNamedQuery(queryName)
Dewfy
Thanks a lot, Dewfy. This works perfectly fine.
venomrld