JPA Entity is unknown when using the @Model annotation
verborghs Jan 14, 2010 10:43 PMI have a class Employee:
@Entity @Model public class Employee implements Serializable { @Id private String name; private String email; private int yearsOfService; /* getters and setters */ }
a class EmployeeDao:
public class EmployeeDao { @PersistenceContext private EntityManager em; @Resource private UserTransaction tx; public List<Employee> list() { return em.createQuery("SELECT e FROM Employee e").getResultList(); } public void save(Employee employee) { try { tx.begin(); em.persist(employee); tx.commit(); } catch (Exception ex) { Logger.getLogger(EmployeeDao.class.getName()).log(Level.SEVERE, null, ex); } } }
a class SaveAction:
@Named("save") @RequestScoped public class SaveAction { @Inject private Employee employee; @Inject private EmployeeDao employeeDao; public SaveAction() { } public String execute() { employeeDao.save(employee); 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" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>New Employee</title> </h:head> <h:body> <ui:debug hotkey="d"/> <h:form> <h:messages/> <h:outputLabel value="Name:"/> <h:inputText value="#{employee.name}"/> <br/> <h:outputLabel value="Email:"/> <h:inputText value="#{employee.email}"/> <br/> <h:commandButton action="#{save.execute}" value="Save!"/> </h:form> </h:body> </html>
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.