7 Replies Latest reply on Jul 30, 2009 11:37 AM by v.lukoyanov

    entity classes not being mapped in war project

    ianmichell

      Hi,


      I'm doing a seam war project, that uses entity transactions. It seems that hibernate is not finding my entity classes (which are annotated correctly and in /WEB-INF/classes/). Does anyone know why hibernate doesn't work properly in a seam war project? Is it hibernate or is it seam?


      Typically I would use full JTA in jboss, but this is a project that I need to be very low memory, so help would be appreciated, I don't want to have to embed jboss into tomcat...


      I'm having the same problem with my unit tests, even with JTA transactions configured in the persistence.xml.

        • 1. Re: entity classes not being mapped in war project
          v.lukoyanov

          Please show your persistence.xml and Tomcat startup logs.

          • 2. Re: entity classes not being mapped in war project
            ianmichell

            Don't have any recent logs of tomcat as I've started refactoring the project... Here is the persistence.xml that works:



            <?xml version="1.0" encoding="UTF-8"?>
            <!-- Persistence deployment descriptor for dev profile -->
            <persistence version="1.0" 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">
              <persistence-unit name="pungwe" transaction-type="RESOURCE_LOCAL">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <non-jta-data-source>java:comp/env/PungweDatasource</non-jta-data-source>
                <class>com.pungwe.model.security.Role</class>
                <class>com.pungwe.model.security.User</class>
                <class>com.pungwe.model.security.log.SecurityLog</class>
                <exclude-unlisted-classes>false</exclude-unlisted-classes>
                <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                  <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:/pungweEntityManagerFactory"/> -->
                </properties>
              </persistence-unit>
            </persistence>





            And here is the one that doesn't




            <?xml version="1.0" encoding="UTF-8"?>
            <!-- Persistence deployment descriptor for dev profile -->
            <persistence version="1.0" 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">
              <persistence-unit name="pungwe" transaction-type="RESOURCE_LOCAL">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <non-jta-data-source>java:comp/env/PungweDatasource</non-jta-data-source>
                <exclude-unlisted-classes>false</exclude-unlisted-classes>
                <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                  <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:/pungweEntityManagerFactory"/> -->
                </properties>
              </persistence-unit>
            </persistence>



            • 3. Re: entity classes not being mapped in war project
              ianmichell

              Now the strange thing is, that hibernate is creating all the tables in the database with no problem, I can run a query like:



              SELECT u FROM User




              And I get a result list back, however if I do:



              getEntityManager().createQuery("FROM User u WHERE u.username = :username")
                       .setParameter("username", username).getSingleResult();




              It will complain that it cannot find the named parameter username. Basically my unit tests fail on jboss embedded as well because of this. As soon as I add the class to the persistence.xml it works.


              I have a separate project for work, which is a full ejb solution using JTA on jboss 5, I don't get this problem in the unit tests, I don't get the problem running in tomcat with jboss embedded, I don't get the problem with the full application server.


              Strange yes?

              • 4. Re: entity classes not being mapped in war project
                v.lukoyanov

                Yes, it's definitely strange.
                I've got almost identical persistence.xml file in my project (works fine), except this line



                <exclude-unlisted-classes>false</exclude-unlisted-classes>



                Looks like your problem is related to http://opensource.atlassian.com/projects/hibernate/browse/EJB-224


                Try to remove that line.

                • 5. Re: entity classes not being mapped in war project
                  ianmichell

                  OK after more work on this, it seems that hibernate hates entity classes when in RESOURCELOCAL, I've split off the entity classes and META-INF into their own JAR, JTA works (as is the case in my JTA project), resourcelocal only half works, where the tables are created, but you can't do any proper queries unless you list the classes manually in the persistence.xml... Surely someone would have picked that up a long time ago, I've used different versions of hibernate and can replicate the problem...

                  • 6. Re: entity classes not being mapped in war project
                    ianmichell

                    I thought it may have been that as well and removed it to no effect, which is a pity... At least jboss-embedded is throwing a better error: java.lang.IllegalArgumentException: Not an entity:class com.pungwe.model.security.User


                    As soon as you put it into tomcat, you get parameter not found... It just strikes me as odd... Could it be java 6?

                    • 7. Re: entity classes not being mapped in war project
                      v.lukoyanov

                      Take a look at seam/examples/jpa sample project. I've been using it as a skeleton. And try to reduce your project to a minimum required classes like just one entity file and one test file, then check and compare to the sample. Hope this will help.