Error reading 'managed' on type ...
chopin Sep 15, 2009 4:35 PMHello,
To get familiar with the application framework of Seam, I extended the registration example by the code fragments of the application framework chapter of the Seam reference manual. Everything seems to be fine. Unfortunately I am getting the following error when I want to update or delete a data record:
Error reading 'managed' on type org.jboss.seam.example.registration.PersonHome$$javassistseam2
I changed the following in the registration example:
- Entity manager registered in persitence.xml
- Persistence context registered in components.xml
- Person.java and PersonHome.java created
- pages.xml added to WEB-INF
- personEditor.xhtml added to war
Searching the web for this error message links all the time to the old seam-gen issue. Doing it a second time didn't help eather.
Any ideas or suggestions to solve this issue?
Thank you in advance for your help.
Please find below the files I changed or added:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/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"> <persistence-unit name="userDatabase"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactories/personData"/> </properties> </persistence-unit> </persistence>
components.xml:
<?xml version="1.0" encoding="UTF-8"?> <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd"> <core:init jndi-pattern="jboss-seam-registration/#{ejbName}/local"/> <persistence:managed-persistence-context name="personDatabase" auto-create="true" persistence-unit-jndi-name="java:/EntityManagerFactories/personData"/> </components>
Person.java:
package org.jboss.seam.example.registration; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @Entity public class Person { @Id @GeneratedValue private Long id; private String firstName; private String lastName; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } }
PersonHome.java:
package org.jboss.seam.example.registration; import javax.persistence.EntityManager; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.framework.EntityHome; @Name("personHome") public class PersonHome extends EntityHome<Person> { private static final long serialVersionUID = -5065906765292941496L; @In EntityManager personDatabase; public EntityManager getEntityManager() { return personDatabase; } @Factory("person") public Person initPerson() { return getInstance(); } }
pages.xml:
<?xml version="1.0" encoding="UTF-8"?> <pages xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd" no-conversation-view-id="/editPerson.xhtml" login-view-id="/home.xhtml"> <page view-id="/editPerson.xhtml"> <param name="personId" value="#{personHome.id}"/> </page> <page view-id="*"> <navigation from-action="#{identity.logout}"> <redirect view-id="/home.xhtml"/> </navigation> <navigation from-action="#{hotelBooking.cancel}"> <redirect view-id="/main.xhtml"/> </navigation> </page> <exception class="org.jboss.seam.security.NotLoggedInException"> <redirect view-id="/home.xhtml"> <message severity="warn">You must be logged in to use this feature</message> </redirect> </exception> <exception class="javax.faces.application.ViewExpiredException"> <redirect view-id="/home.xhtml"> <message severity="warn">Session expired, please log in again</message> </redirect> </exception> </pages>
editPerson.xhtml:
<?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:s="http://jboss.com/products/seam/taglib" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <head> <title>Register New User</title> </head> <body> <f:view> <h1> <h:outputText rendered="#{!personHome.managed}" value="Create Person"/> <h:outputText rendered="#{personHome.managed}" value="Edit Person"/> </h1> <h:form> <div>First name: <h:inputText value="#{person.firstName}"/></div> <div>Last name: <h:inputText value="#{person.lastName}"/></div> <div> <h:commandButton value="Create Person" action="#{personHome.persist}" rendered="#{!personHome.managed}"/> <h:commandButton value="Update Person" action="#{personHome.update}" rendered="#{personHome.managed}"/> <h:commandButton value="Delete Person" action="#{personHome.remove}" rendered="#{personHome.managed}"/> </div> </h:form> </f:view> </body> </html>