[jboss-user] [EJB 3.0] - EntityManager is null

kgreene do-not-reply at jboss.com
Thu Feb 14 14:58:00 EST 2008


Hi,

I'm trying to create a class that does database retrieval using entity manager. When I call getVpInfo, I notice that the entity manager is null. I need to access this dao from another class in my app. I am not accessing the dao from the client-side code.

Does anyone know why the entity manager is null. I have also included my persistence.xml

=======

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

@Stateless
public class VpInfoDAOBean implements VpInfoDAORemote, VpInfoDAOLocal{

	@PersistenceContext  (unitName="VPInfoDB")
	protected EntityManager em;
		
	private static VpInfoDAOBean dao = new VpInfoDAOBean();
	
	public static VpInfoDAOBean getInstance() {return dao;}
	
	public VpInfo getVpInfo(String appGroup) 
	{
		if (em == null)
			System.out.println("Vp em is null");
		return (VpInfo)em.createQuery(
	      "from VpInfo v where v.appGroup = :appGroup").setParameter("appGroup", appGroup).getSingleResult();

	}
	
	
	
	
}

================================
persistence.xml


  <persistence-unit name="VealMonitorDB">
    <jta-data-source>java:/DefaultDS</jta-data-source>
    
    <!-- 
      
         -->
      <!--  -->
    
  </persistence-unit>
  <persistence-unit name="VPInfoDB">
    <jta-data-source>java:/DefaultDS</jta-data-source>
    
    <!-- 
      
         -->
      <!--  -->
    
  </persistence-unit>


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

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



More information about the jboss-user mailing list