1 2 Previous Next 20 Replies Latest reply on Aug 7, 2013 2:12 AM by shailu777

    WAR and JPA no entities scanned

    rlogiacco

      Hi, I'm trying to deploy in JBoss AS7.1.1.Final a war which contains annotated entities. It seems the entities contained in the WEB-INF/classes directory are not scanned.

       

      I've tried two different approaches: with container managed JPA and with application managed JPA (within Spring) and neither of the two works while the latter works perfectly fine in Tomcat.

       

      My persistence.xml file (which get's renamed to jpa-persistence.xml when I switch to application managed JPA) content is:

       

      {code:xml}<?xml version="1.0" encoding="UTF-8" standalone="no"?>

      <persistence version="2.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_2_0.xsd"

      >

       

       

        <persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">

          <provider>org.hibernate.ejb.HibernatePersistence</provider>

          <non-jta-data-source>java:jboss/datasources/TalentDS</non-jta-data-source>

       

          <!-- this should not be necessary! if I add them then everything goes fine

          <class>org.agileware.talent.Account</class>

          <class>org.agileware.talent.Application</class>

          <class>org.agileware.talent.Candidate</class>

          <class>org.agileware.talent.Experience</class>

          <class>org.agileware.talent.Offer</class>   

          -->

       

          <properties>

            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />

            <!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop"

              means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->

            <property name="hibernate.hbm2ddl.auto" value="create" />

            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />

            <property name="hibernate.connection.charSet" value="UTF-8" />

            <property name="hibernate.validator.apply_to_ddl" value="false" />

            <property name="hibernate.validator.autoregister_listeners" value="false" />

       

            <!-- I've tried with and without the following, no joy and I don't even know what it does-->

            <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/LibraryEntityManagerFactory" />

          </properties>

        </persistence-unit>

      </persistence>

      {code}

       

      Obviously if I have the file named persistence.xml and I leave the spring configuration as it is my persistenceUnit is processed twice, once by JBoss and once by Spring.

      What am I missing?

        • 1. Re: WAR and JPA no entities scanned
          smarlow

          Is the container managed JPA, also using Spring?  I wasn't sure if you were using Spring for both.

           

          If the container manager JPA is not using Spring, I would enable TRACE logging for org.hibernate and org.jboss.as.jpa (see https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Troubleshooting) and look for clues in the server.log (the org.jboss.as.jpa entity scanning code has logging in it).

           

          Scott

          • 2. Re: WAR and JPA no entities scanned
            rlogiacco

            I'm not sure what you mean but the application is created with Spring Roo which means it's entirely based on Spring. When I switched to container managed JPA I had my persistence.xml file and everything was pointing to the JBoss created persistence unit and data source.

            Does this answer your question?

            • 3. Re: WAR and JPA no entities scanned
              smarlow

              Yes, you answered my question. 

               

              I think this link is current down, but checkout https://docs.jboss.org/author/display/AS71/Spring+applications+development+and+migration+guide in a few minutes.  Also, another link about Spring applications running on AS7 is https://community.jboss.org/blogs/mariusb/2011/07/13/spring-and-jboss-as7-part-1-getting-started.

              • 4. Re: WAR and JPA no entities scanned
                rlogiacco

                I will but I doubt the problem is related to Spring as in a container managed JPA the entities scan should be performed by JBoss, not by Spring so I guess I'm missing some sort of JBoss configuration. Anyway I'll give a look at the links you provided in a while and I want to thank you for your help.

                • 5. Re: WAR and JPA no entities scanned
                  vmikulcic

                  Having the same problem, and the same project works fine without manually listing <class>...</class> when run on Tomcat.

                  • 6. Re: WAR and JPA no entities scanned
                    ctomc

                    Can you prepare sample application that reproduces the problem?

                     

                     

                    --

                    tomaz

                    • 7. Re: WAR and JPA no entities scanned
                      nickarls

                      Also, please do a jar tf foo.war and show the layout. Having extra stuff (e.g. Hibernate jars) in the lib might have undesirable effects.

                      • 8. Re: WAR and JPA no entities scanned
                        jaikiran

                        Are you using the Hibernate version (4) bundled in AS7 or are you using Hibernate version 3.3.x. This question recently came up here https://community.jboss.org/thread/205012?tstart=180

                        • 9. Re: WAR and JPA no entities scanned
                          vmikulcic

                          Project that has the mentioned problem:

                          https://docs.google.com/open?id=0BxIzMpeayz9nSmc4Z3dnVS04V0k

                           

                          The hibernate dependencies are marked with <scope>provided</scope> in Maven, and are not included in the war file.

                          • 10. Re: WAR and JPA no entities scanned
                            ctomc

                            What happens if your remove jpa subsystem from standalone.xml?

                             

                             

                            --

                            tomaz

                            • 11. Re: WAR and JPA no entities scanned
                              vmikulcic

                              Works exactly the same as before...

                               

                              <!--

                                <subsystem xmlns="urn:jboss:domain:jpa:1.0">
                                          <jpa default-datasource=""/>
                                      </subsystem>

                              -->

                              • 12. Re: WAR and JPA no entities scanned
                                ctomc

                                Hi,

                                 

                                I was playing around and tried to deploy your application in various ways including changing bunch of configurations and repacked with different versions of liberies

                                and i had no success, all i managed to do is to trace problem down to spring and the way it is integrating with JPA. instead of just leting APP server deploy JPA entity manager and then use it, it tries to re-initialize everything. For proof of that remove <provider> tag in persistence.xml as it is optional and tells app container to use default one but in your case, spring dies as now it does not know how to configure entityManager as there is no provider specifed.

                                I think it should just leave initizaliation to container and then use configured entitymanager.

                                 

                                That said, there probably is some workaround that i have not found. It must be somewhare in configuration of Spring but which I don't know in details.

                                 

                                Marius Bogoevici might be able to help given that mentains project SnowDrop that focuses on Spring <-- --> AS integration.

                                 

                                --

                                tomaz

                                • 13. Re: WAR and JPA no entities scanned
                                  ctomc

                                  problem is in the way you have spring configured.

                                   

                                  You have spring configured to mange whole entityManager but fails to do that becouse it does not know how to properly scan annotated classes (it should use jandex).

                                   

                                  I have changed configuration to let spring use entityManager that is deployed & managed by application server, that way it works without any issues.

                                   

                                  i have changed persistence.xml to:

                                   

                                  <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                                  <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_2_0.xsd"
                                               version="2.0">
                                  
                                      <persistence-unit name="iraPersistenceUnit" transaction-type="RESOURCE_LOCAL">
                                          <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                          <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
                                  
                                          <properties>
                                              <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>
                                              <property name="hibernate.generate_statistics" value="true"/>
                                              <property name="jboss.entity.manager.factory.jndi.name" value="java:app/iraEntityManagerFactory"/>
                                          </properties>
                                  
                                      </persistence-unit>
                                  
                                  </persistence>
                                  

                                   

                                  and applicationContext.xml to

                                   

                                  <?xml version="1.0" encoding="UTF-8"?>
                                  <beans xmlns="http://www.springframework.org/schema/beans"
                                         xmlns:p="http://www.springframework.org/schema/p"
                                         xmlns:tx="http://www.springframework.org/schema/tx"
                                         xmlns:context="http://www.springframework.org/schema/context"
                                         xmlns:jee="http://www.springframework.org/schema/jee"
                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                         xsi:schemaLocation="http://www.springframework.org/schema/beans
                                                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                                             http://www.springframework.org/schema/context
                                                             http://www.springframework.org/schema/context/spring-context-3.0.xsd
                                                             http://www.springframework.org/schema/jee
                                                               http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                                                             http://www.springframework.org/schema/tx
                                                             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                                  
                                  
                                      <!-- Basic DataSource -->
                                      <bean id="dataSource"
                                            class="org.springframework.jndi.JndiObjectFactoryBean"
                                            p:jndiName="java:jboss/datasources/ExampleDS"/>
                                  
                                      <context:component-scan base-package="com.ms.test.prime"/>
                                  
                                      <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:app/iraEntityManagerFactory"/>
                                      <!-- Transaction Config -->
                                      <bean id="transactionManager"
                                            class="org.springframework.orm.jpa.JpaTransactionManager"
                                            p:entityManagerFactory-ref="entityManagerFactory"/>
                                  
                                      <tx:annotation-driven transaction-manager="transactionManager"/>
                                  
                                      <context:annotation-config/>
                                  
                                  
                                  </beans>
                                  

                                   

                                  I have removed other stuff as it was not needed.

                                   

                                  --

                                  tomaz

                                  • 14. Re: WAR and JPA no entities scanned
                                    eruiz

                                    Tomaz, you found a workaround, but not a solution to the problem.

                                     

                                    I have the same problem with Spring 3.2 apps. The problem is a Servlet compliant WAR cannot be deployed in JBoss 7.1, I think it is related to the new ClassLoader architecture.

                                     

                                    Regards

                                    1 2 Previous Next