[jboss-user] [EJB3] - EntityManager.find returns null.

Joseph Hwang do-not-reply at jboss.com
Mon May 16 01:09:36 EDT 2011


Joseph Hwang [http://community.jboss.org/people/aupres] created the discussion

"EntityManager.find returns null."

To view the discussion, visit: http://community.jboss.org/message/605376#605376

--------------------------------------------------------------
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....
 
 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

-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();
        }
    }
}
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 ...
There is no Exception.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/605376#605376]

Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110516/f7e63ba6/attachment.html 


More information about the jboss-user mailing list