title: define named query in orm.xml with jpa and hibernate
body: <p>I'm trying to put my named queries in my orm.xml (put in META-INF with persistence.xml) but my orm.xml seems to be ignored by hibernate/jpa. </p>
  
  <p>When I try to create my named query with em.createNamedQuery("myQuery"), it returns that it can't find this query.</p>
  
  <p>I use annotation and I would like to externalize my named queries in orm.xml (only that).</p>
  
  <p>Here is my persistence.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
  
  &lt;persistence-unit name="default" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;mapping-file&gt;META-INF/orm.xml&lt;/mapping-file&gt;
  
      &lt;class&gt;com.mysite.Account&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" /&gt;
          &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt;
          &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;property name="use_sql_comments" value="false" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MYSQLDialect" /&gt;
          &lt;property name="hibernate.c3p0.min_size" value="5" /&gt;
          &lt;property name="hibernate.c3p0.max_size" value="20" /&gt;
          &lt;property name="hibernate.c3p0.timeout" value="300" /&gt;
          &lt;property name="hibernate.c3p0.max_statements" value="50" /&gt;
          &lt;property name="hibernate.c3p0.idle_test_period" value="3000" /&gt;
  
          &lt;property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider" /&gt;
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>here is my orm.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" version="1.0"&gt;
  
  &lt;package&gt;com.mysite&lt;/package&gt;
  
  &lt;entity class="Account"&gt;
      &lt;sql-result-set-mapping name="nicknames"&gt;
          &lt;column-result name="nickname" /&gt;
      &lt;/sql-result-set-mapping&gt;
      &lt;table name="Account" /&gt;
      &lt;named-native-query name="myQuery" result-set-mapping="nicknames"&gt;
          &lt;query&gt;&lt;![CDATA[select a.nickname from Account a]]&gt;
      &lt;/query&gt;
      &lt;/named-native-query&gt;
  &lt;/entity&gt;
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>What I'm doing wrong ? Why my orm.xml is ignored ?</p>
  
  <p>thanks</p>