3 Replies Latest reply on Dec 22, 2011 6:46 AM by Nicklas Karlsson

    java.lang.IllegalArgumentException: Named query not found

    Joseph Hwang Novice

      I try to call stored procedure in MySQL 5. I use jboss7 and eclipse indigo.My codes are

       

      @Stateless
      public class CallStoredProcedureBean implements ICallStoredProcedurePort {

         @PersistenceContext(unitName="MyFamily")
         EntityManager em;

       

         @Override
         public Object callSP(String ID) {
            Query query = em.createNamedQuery("findFamilyMember"); //throws exception
            query.setParameter("EMP_ID", ID);
            Members result = (Members)query.getSingleResult();
       
            return result;
         }

      }

       

      ================

      import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
      import org.eclipse.persistence.annotations.StoredProcedureParameter;
      import org.eclipse.persistence.annotations.Direction;

       

      @Entity
      @Table(name="family")
      @NamedStoredProcedureQuery(name="findFamilyName", procedureName="SP_SELECT_MYSQL", resultClass=Members.class,
          parameters={
             @StoredProcedureParameter(queryParameter="EMP_ID", type=String.class),
             @StoredProcedureParameter(queryParameter="EMP_IDENTITY",direction=Direction.OUT, type=String.class),
             @StoredProcedureParameter(queryParameter="EMP_PASSWD",direction=Direction.OUT, type=String.class),
             @StoredProcedureParameter(queryParameter="EMP_NAME",direction=Direction.OUT, type=String.class)
      })
      public class Members implements Serializable {

       

         @Id
         @GeneratedValue(strategy=GenerationType.IDENTITY)
         @Column(name = "EMP_ID")
          private String ID;

         @Column(name = "EMP_Passwd")
          private String Passwd;

          @Column(name = "EMP_Name")
           private String Name;

      ..........

      =====================

      persistence.xml code is like below

       

      <persistence version="1.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_1_0.xsd">

         <persistence-unit name="MyFamily">
            <jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>

            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="update"/>        
               <property name="hibernate.show_sql" value="true"/>
            </properties>
         </persistence-unit>
      </persistence>

       

      CreateNamedQuery throws java.lang.IllegalArgumentException: Named query not found: findFamilyMember.

       

      I don't know what is wrong on my codes. Pls, give your advice. Thanks in advanced.