4 Replies Latest reply on May 19, 2011 9:23 AM by Wolfgang Knauf

    EntityManager.find returns null.

    Joseph Hwang Novice

       

      My developmet environment is

       

        OS : Linux CentOS 5.6
        JDK : JDK 1.6
        JBoss : JBoss 5.1.0.GA
        DB : Oracle 11g

       

      EntityManager.find method always returns null. Same source is executed good on Windows Server 2008 and SQL Server 2008.

      Codes are

      -Members.java(Entity)-

      package com.aaa.ejb3;

      import java.io.Serializable;

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;

      @Entity
      @Table(name = "family")
      public class Members implements Serializable {
          @Id
          @Column(name = "EMP_ID")
          private String ID;
        
          @Column(name = "EMP_Passwd")
          private String Passwd;
        
          @Column(name = "EMP_Name")
          private String Name;
      ....getter와 setter method....

       

       

      -EJBLoginBean.java(Session Bean)-

      package com.aaa.ejb3;

       

      import javax.ejb.Stateless;

      import javax.persistence.EntityManager;

      import javax.persistence.PersistenceContext;

       

      @Stateless

      public class EJBLoginBean implements IEJBLogin {

       

          @PersistenceContext(unitName="MyDBTest")

         EntityManager em;

         

          public Object loginFunc(Class clazz, Object primaryKey) {

              // TODO Auto-generated method stub

              Object obj = em.find(clazz, primaryKey);

              System.out.println(obj); // always returns null

              return em.find(clazz, primaryKey);

          }

       

      }

       

      - WSLoginTest.java(EJB invocation)-

      @WebService

      public class WSLoginTest implements WSLoginTestPort {

         

          @EJB

          IEJBLogin login;

       

          public String loginFunc(String ID, String Passwd) {

       

       

       

       

             // TODO Auto-generated method stub

             try {

       

                  Members member = new Members();

                  member = (Members)login.loginFunc(Members.class, ID); // I tried ID.trim() but failed                     

                  if( member == null )

                      return "no user"; //always return this value

                  else if(!Passwd.equals(member.getPasswd().trim()))

                      return "wrong password.";

                      else

                          return member.toString();

              }

              catch(Exception e) {

                  return e.getMessage();

       

              }

       

          }

       

       

      }

       

       

       

       

       

      There is no Exception.

       

       

      in console

       

      13:47:37,381 INFO  [SessionFactoryObjectFactory] Factory name: persistence.unit:unitName=TotalTestEAR.ear/EJBLoginModule.jar#MyDBTest

       

       

      .....

      13:47:48,492 INFO  [SchemaUpdate] updating schema

      13:47:57,430 INFO  [TableMetadata] table found: SCOTT.FAMILY

      13:47:57,430 INFO  [TableMetadata] columns: [emp_passwd, emp_name, emp_id]

       

      JBoss recognized Entity

       

      Through STDOUT


      13:48:53,875 INFO  [STDOUT] Hibernate: select members0_.EMP_ID as EMP1_2_0_, members0_.EMP_Name as EMP2_2_0_, members0_.EMP_Passwd as EMP3_2_0_ from family members0_ where members0_.EMP_ID=?
      13:48:53,951 INFO  [STDOUT] null
      13:48:53,952 INFO  [STDOUT] Hibernate: select members0_.EMP_ID as EMP1_2_0_, members0_.EMP_Name as EMP2_2_0_, members0_.EMP_Passwd as EMP3_2_0_ from family members0_ where members0_.EMP_ID=?

       

       

      SQL select is done well and there is no exception, but why EntityManager.find returns null?
      When I execute EntityManager.persist, insert SQL is generated and values are inserted to Oracle DB!!!!

       

      I need your advice ! Thanks in advance

       

      Best Regards