[jboss-user] [EJB 3.0] - EJB3 entity bean query always returns null

mxshrestha do-not-reply at jboss.com
Sun Mar 8 17:15:57 EDT 2009


I have had this problem for a month now. I am trying to execute a JPA query from a session bean, and everytime it returns only null. Other functionalities of the entity bean like persist() works, and stores database. What am i doing wrong here. My code is attached below:


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless

public class LoginBean implements LoginBeanRemote, LoginBeanLocal {

	public LoginBean() {
    
    }
	
	@PersistenceContext(unitName="CustomerUnit")
	EntityManager manager;
	
    public String validateLogin(String userName, String password)
    {
    	try
    	{
       		Query q1 = manager.createQuery("SELECT c FROM Customer c WHERE c.userName = :username AND c.password = :password ");
    		q1.setParameter("username", userName);
    		q1.setParameter("password", password);
    		System.out.println(q1.getSingleResult());
    		
    	}
    	catch(Exception e)
    	{
    		e.printStackTrace();
    	}
    	
    	return "loginUser";
    }
}


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4216028#4216028

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4216028



More information about the jboss-user mailing list