0 Replies Latest reply on Nov 10, 2009 2:05 PM by anibals

    Seam 2.2.0.GA and JPA on AS 5.1

    anibals

      It's a little odd to discover that seam-gen (generate entities) is not working out of the box with JBoss AS 5.1.


      Anyway... if you hit these errors:


      javax.el.ELException: javax.persistence.NoResultException: No entity found for query


      or


      javax.el.ELException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: (Object) is not mapped


      or


      (If you try fix the absolut path of the class)
      Caused by: javax.persistence.NoResultException: No entity found for query




      The problem is at the JPA Entity Manager.


      The reason is AS 5.1 changes the way the Entity Manager is instantiated.... and seam-gen is still generating the code with the old way.


      A first clue:
      https://jira.jboss.org/jira/browse/JBSEAM-3821


      In the bug, the workaround is not clear.


      I recommend to deploy the example jboss-seam-jpa, at the example directory ant jboss5 (remember to change the properties file).


      The example is working Ok.


      So you can paste the right sentences to persistence.xml and components.xml.


      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="bookingDatabase" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <non-jta-data-source>java:/DefaultDS</non-jta-data-source>
            <properties>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                 <!-- Binds the EntityManagerFactory to JNDI where Seam can look it up.
                    This is only relevant when the container automatically loads the persistence unit, as is the case in JBoss AS 5. -->
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/bookingEntityManagerFactory"/>
            </properties>
         </persistence-unit>
      </persistence>



      components.xml


      ...


         <transaction:entity-transaction entity-manager="#{em}"/>
                        
          <persistence:entity-manager-factory name="bookingDatabase" installed="false"/>
      
          <!-- If Seam loads the persistence unit (JBoss 4.x), the EntityManagerFactory will be resolved from #{bookingDatabase}.
               On JBoss AS 5, the EntityManagerFactory is retrieved from JNDI (the binding occurs during application deployment). -->
          <persistence:managed-persistence-context name="em" auto-create="true"
             entity-manager-factory="#{bookingDatabase}" persistence-unit-jndi-name="java:/bookingEntityManagerFactory"/>


      ...                   



      I hope this post will save your precious time ;-)


      Thanks,
      Anibal