0

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 <mapping-file> in persistence.xml and tried to place the query file in several locations. Every time I am getting exception.

Lucky
  • 16,787
  • 19
  • 117
  • 151
jagbandhuster
  • 677
  • 2
  • 7
  • 20
  • possible duplicate of [define named query in orm.xml with jpa and hibernate](http://stackoverflow.com/questions/2373369/define-named-query-in-orm-xml-with-jpa-and-hibernate) – Pascal Thivent Oct 16 '10 at 11:52

1 Answers1

1

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 define named query in orm.xml with jpa and hibernate). In the last case you can even use:

 EntityManager.createNamedQuery(queryName)
Community
  • 1
  • 1
Dewfy
  • 23,277
  • 13
  • 73
  • 121