0 Replies Latest reply on Aug 4, 2007 6:25 PM by kurzweil4

    Web Page Having Trouble Connecting to EJB 3.0 Enity

    kurzweil4

      I have an application with a Model and a View project. The bean in the View project is having trouble finding the EJB Enity in the Model project. The binding DepartmentsBean.departments is failing with this error:

      javax.el.ELException: javax.faces.el.EvaluationException: javax.el.ELException: Error reading 'departments' on type ice.data.table.view.DepartmentsBean


      I had the EXACT same error when I was deploying to OC4J, but the problem was that my Model project was not deployed as an EJB Jar. That is not the problem in this case since I am now using en EJB Jar.

      Also, I have tested my DB connection with a plain JSP manually querying a table in the DB, so I know my connection configuration is good.

      This is my persistence.xml:

      <?xml version="1.0" encoding="windows-1252" ?>
      <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
       <persistence-unit name="Model">
       <jta-data-source>java:/hr</jta-data-source>
       <class>ice.data.table.model.Departments</class>
       <class>ice.data.table.model.DepPublicFacade</class>
       <class>ice.data.table.model.DepPublicFacadeLocal</class>
       <class>ice.data.table.model.DepPublicFacadeBean</class>
       </persistence-unit>
      </persistence>
      


      This is my entity:

      @Entity
      @NamedQuery( name = "Departments.findAll",
       query = "select o from Departments o" )
      public class Departments implements Serializable
      {
       @Id
       @Column( name="DEPARTMENT_ID", nullable = false )
       private Long departmentId;
       @Column( name="DEPARTMENT_NAME", nullable = false )
       private String departmentName;
       @Column( name="LOCATION_ID" )
       private Long locationId;
       @Column( name="MANAGER_ID" )
       private Long managerId;
      
       public Departments()
       {
       }
      
       public Long getDepartmentId()
       {
       return departmentId;
       }
      
       public void setDepartmentId( Long departmentId )
       {
       this.departmentId = departmentId;
       }
      
       public String getDepartmentName()
       {
       return departmentName;
       }
      
       public void setDepartmentName( String departmentName )
       {
       this.departmentName = departmentName;
       }
      
       public Long getLocationId()
       {
       return locationId;
       }
      
       public void setLocationId( Long locationId )
       {
       this.locationId = locationId;
       }
      
       public Long getManagerId()
       {
       return managerId;
       }
      
       public void setManagerId( Long managerId )
       {
       this.managerId = managerId;
       }
      }
      


      This is my facade:

      @Stateless( name="DepPublicFacade" )
      public class DepPublicFacadeBean implements DepPublicFacade, DepPublicFacadeLocal
      {
       @PersistenceContext( unitName="Model" )
       private EntityManager em;
      
       public DepPublicFacadeBean()
       {
       }
      
       public Object mergeEntity( Object entity )
       {
       return em.merge(entity);
       }
      
       public Object persistEntity( Object entity )
       {
       em.persist(entity);
       return entity;
       }
      
       /** <code>select o from Departments o</code> */
       public List<Departments> queryDepartmentsFindAll()
       {
       return em.createNamedQuery("Departments.findAll").getResultList();
       }
      
       public void removeDepartments( Departments departments )
       {
       departments = em.find(Departments.class, departments.getDepartmentId());
       em.remove(departments);
       }
      }
      


      This is my bean from the View project:

      public class DepartmentsBean
      {
       private DepPublicFacade model;
      
       public DepartmentsBean()
       {
       try
       {
       final Context context = getInitialContext();
       model = (DepPublicFacade)context.lookup("DepPublicFacade");
       }
       catch (Exception ex)
       {
       ex.printStackTrace();
       }
       }
      
       public List getDepartments()
       {
       return model.queryDepartmentsFindAll();
       }
      
       private static Context getInitialContext() throws NamingException
       {
       // Get InitialContext for Embedded OC4J
       // The embedded server must be running for lookups to succeed.
       return new InitialContext();
       }
      }
      


      Any help or pointers to information would be appreciated. I am at a loss here.

      Thanks,
      Kurzweil4