0 Replies Latest reply on May 11, 2006 6:04 AM by Richie

    A exception with : org.hibernate.MappingException: Named que

    Richie Newbie

      A exception with : org.hibernate.MappingException: Named query not known.
      When my Servlet invoke like this:

      try {
       InitialContext ctx = new InitialContext();
       log.info("InitialContext ctx = new InitialContext();");
       userFacad
       log.info("userFacade =e = (UserFacadeService) ctx.lookup("UserFacade/local"); (UserFacadeService) ctx.lookup(\"UserFacade/local\");");
       } catch (Exception e) {
       e.printStackTrace();
       log.info(e);
       }
       userFacade.regUser(new User(userName, password));

      Jboss Server throw exception like that:

      exception
      
      javax.ejb.EJBTransactionRolledbackException: javax.persistence.PersistenceException: org.hibernate.MappingException: Named query not known: findUserByName
       org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:89)
       org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
       org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
       $Proxy86.findByName(Unknown Source)
       richie.gt.ejb3.facade.UserFacade.regUser(UserFacade.java:37)


      I don't know why it happened.Help~~This is UserFacade Class.
      public User regUser(User user) {
       /**
       * save a new User
       */
       if (um.findByName(user.getUserName()) != null)
       return null;
       um.save(user);
       return um.findByName(user.getUserName());
       //um is a instance of UserManager class
       }

      This is UserManager Class:
      @NamedQueries( {
       @NamedQuery(name = "findUserByName", query = "SELECT u FROM User u WHERE u.userName = : userName")})
      @Stateless
      @Local( { richie.gt.ejb3.service.UserManagerService.class })
      public class UserManager implements UserManagerService {
      
       @PersistenceContext
       protected EntityManager em;
      
       /**
       * findByName (Func)
       */
       public User findByName(String userName) {
       return (User) em.createNamedQuery("findUserByName").setParameter(
       "userName", userName).getSingleResult();
      
       }
      


      This is persistence.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence>
       <persistence-unit name="gt">
       <jta-data-source>java:MySqlDS</jta-data-source>
       <class>richie.gt.ejb3.manager.UserManager</class>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop" />
       <property name="show_sql">true</property>
       <property name="current_session_context_class">thread</property>
       <property name="connection.pool_size">1</property>
       </properties>
       </persistence-unit>
      </persistence>
      


      Thank you~ your attention