13 Replies Latest reply on Jan 27, 2010 1:29 PM by steven verborgh

    JPA Entity is unknown when using the @Model annotation

    steven verborgh Newbie

      I have a class Employee:

      public class Employee implements Serializable {
          private String name;
          private String email;
          private int yearsOfService;
          /* getters and setters */

      a class EmployeeDao:

      public class EmployeeDao {
          private EntityManager em;
          private UserTransaction tx;
          public List<Employee> list() {
              return em.createQuery("SELECT e FROM Employee e").getResultList();
          public void save(Employee employee) {
              try {
              } catch (Exception ex) {
                  Logger.getLogger(EmployeeDao.class.getName()).log(Level.SEVERE, null, ex);

      a class SaveAction:

      public class SaveAction {
          private Employee employee;
          private EmployeeDao employeeDao;
          public SaveAction() {
          public String execute() {
              return "index?faces-redirect=true";

      They are used in a jsf facelets page:

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
              <title>New Employee</title>
              <ui:debug hotkey="d"/>
                  <h:outputLabel value="Name:"/>
                  <h:inputText value="#{employee.name}"/>
                  <h:outputLabel value="Email:"/>
                  <h:inputText value="#{employee.email}"/>
                  <h:commandButton action="#{save.execute}" value="Save!"/>

      When running this I get a Exception: Employee is not a known entity type.

      When I remove the @Model annotation, add a getter for employee to the SaveAction class and use an el of #{save.employee.name} and of course also #{save.employee.email} it works as expected.

      In both cases using FINEST logging for eclipselink is see eclipselink saying it is registering the class for weaving and actually also weaving the class.

      So the question is: Is CDI returing a proxy, doing it's own incompatable weaving or an unweaved object when I add the @Model? Is it a bug, or should I not be using the @Entity and @Model on the same class.