Error Rendering View with JBoss AS 5.1, Seam 2.2 and JBoss Tools 3.1

1

May 23, 2010 by huionn

I was following Getting Started Guide for JBoss Tools (http://docs.jboss.org/tools/3.1.0.GA/en/GettingStartedGuide/html/first_seam.htm) to create CRUD web page from database with New > Seam Generate Entities. With Seam 2.2.0GA, JBoss AS 5.1GA and JBoss Tools 3.1GA, an exception was thrown when I accessed the generated page

SEVERE [viewhandler] Error Rendering View[/CustomerList.xhtml]
javax.el.ELException: /CustomerList.xhtml: Error reading ‘resultList’ on type org.domain.jbdswar220cr1v4.session.CustomerList_$$_javassist_seam_2
……
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [select customer from Customer customer]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:601)
……
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [select customer from Customer customer]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
……

I could not google a straightforward solution to this, but it lead me to https://jira.jboss.org/browse/JBSEAM-4276.

<!– If you are still using JBoss 4, uncomment this to have you PU started –>
<!– <persistence:entity-manager-factory name="entityManagerFactory"
                   persistence-unit-name="@projectName@"
                               installed="@seamBootstrapsPu@"/>–>

<persistence:managed-persistence-context name="entityManager" auto-create="true"
                       entity-manager-factory="@seamEmfRef@"
                   persistence-unit-jndi-name="@puJndiName@"/>

So, the root cause is that JBoss 5 uses different mechanism (persistence-unit-jndi-name instead of entity-manager-factory) for managed-persistence-context. After understand it, it is easy to fix the problem. Open the components.xml, edit persistence:managed-persistence-context accordingly.

WEB-INF/components.xml

<persistence:managed-persistence-context name="entityManager" auto-create="true"
                      persistence-unit-jndi-name="java:/workshopEntityManagerFactory"/>

META-INF/persistence.xml

<persistence-unit name="workshop" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/workshopDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <!– Only relevant if Seam is loading the persistence unit (Java SE bootstrap) –>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/workshopEntityManagerFactory"/>
      </properties>
   </persistence-unit>

persistence-unit-jndi-name must be same as jboss.entity.manager.factory.jndi.name (add if it is not there)

 

JBoss Tools and Seam may be developed by different teams and both need to support multiple platform (application servers, web servers, different version of JBoss products), so it is understandable and pardonable to have this kind of problem in release (from the JIRA, it shows that the patch was committed just after GA release). However, at least it should be clearly documented in Getting Started Guide as it will be used by anybody who want to try out Seam. Otherwise I think many people will back off because losing confidence in Seam/JBoss Tools.

Advertisements

One thought on “Error Rendering View with JBoss AS 5.1, Seam 2.2 and JBoss Tools 3.1

  1. Denis says:

    huionn, thanks, your solution was very useful!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: