title: JBoss/Hibernate IllegalArgumentException: Named query not Found
body: <p>I'm new to Java EE and having some trouble using named queries. We use JBoss 6 and Hibernate 3.6 (JPA 2.0). The entity is configured via annotations and not in the persistence.xml:</p>
  
  <pre><code>@Entity
  @NamedQueries({
      @NamedQuery(name = "Node.findRootNodes", query = "SELECT n FROM Node n WHERE n.parent IS NULL OR n.parent = 0"),
      ...
  })
  public class Node implements Serializable { ... }
  </code></pre>
  
  <p>When deploying the jar containing the entity, the JBoss-log tells us, that the named query is bound:</p>
  
  <pre><code>[org.hibernate.cfg.annotations.QueryBinder] Binding Named query: Node.findRootNodes =&gt; SELECT n FROM Node n WHERE n.parent IS NULL OR n.parent = 0
  </code></pre>
  
  <p>Unfortunately, when using the named query, we always run into an IllegalArgumentException:</p>
  
  <pre><code>[com.NodeTest] null: javax.ejb.EJBException: java.lang.IllegalArgumentException: Named query not found: Node.findRootNodes
  </code></pre>
  
  <p>The stateless bean using the named-query is in the same jar as the Node-Entity. The Application calling the stateless bean is in a different war file deployed.</p>
  
  <p>Does anybody has an idea what I do wrong? Thank you for your Answer.</p>
  
  <p>Here is the persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" 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_2_0.xsd"&gt;
      &lt;persistence-unit name="testPU" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; 
          &lt;jta-data-source&gt;java:/main&lt;/jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>