6 Replies Latest reply on Dec 1, 2011 8:22 AM by kwaegema

    migrated war deployed in as7 but no working annotationbinding

    kwaegema

      Hi

       

      I migrated my application war from Jboss 4.2.3 to Jboss 7.0.2 Final.

      I use hibernate 3.5, spring 3.0.5FINAL en struts 2.2.3.1. Those were all added to the lib folder in the .war.

      I already did some problem solving for using the own hibernate 3 (excluded hibernate.org, added property jboss-as-jpa-providerModule, changed location of persistence to jpa-persistence,..). Now it deploys under jboss 7 and I can see some content.

       

      Still the application is not working correctly. Only the content that doesn't need persistence works. An example of an error :

       

      message: Unknown entity: net.straininfo2.entities.AccessLog

      stack: java.lang.IllegalArgumentException: Unknown entity: net.straininfo2.entities.AccessLog at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:671) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native

      ...

       

      The war deploys under Jetty Webserver (and under Jboss 4) so it is something with Jboss 7.

      In Jetty there is this message in the log:

      [AnnotationBinder.java:529] : Binding entity from annotated class: net.straininfo2.entities.AccessLog

      The difference is that Jboss doesn't show this message..!

      There are no errors in the Jboss log and the other messages seem to be quasi the same.

       

      When I add it with <class> in the persistence file, then Jboss binds it (and shows that message).

      But I have about 100 entities, and it doesn't seem a very good practice to do it that way..

       

      Does someone knows why JBoss won't do that automaticly?

       

      Thanks!

      K

        • 1. Re: migrated war deployed in as7 but no working annotationbinding
          prasad.deshpande

          Can you please show how your persistence.xml looks like? Also, where is it placed? What is the location, Also if you could attach server.log file too?

          • 2. Re: migrated war deployed in as7 but no working annotationbinding
            kwaegema

            Structure of webapp.war:

             

            ./WEBINF

                 /lib

                     core.1.0-SNAPSHOT.jar

                      ...

                 ...

            ...

             

             

            The structure of core.1.0-SNAPSHOT.jar:

             

            ./META-INF

                 jpa-persistance.xml (also tried with persistence.xml)

            ./net

                  /straininfo2

                      /entities

                           ...

            applicationContext-core.xml

            ...

             

             

            The persistence.xml /jpa-persistence.xml has 4 persistence units like this:

             

              <persistence-unit name="straininfo2-xenneke">

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

                            <properties>

                                     <property name="hibernate.archive.autodetection" value="class"/> <!-- tested with and without this property-->

                                    <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />

                                    <property name="hibernate.connection.url"

                                            value="jdbc:oracle:thin:@***:***:***" />

             

                                    <property name="hibernate.connection.username" value="***" />

                                    <property name="hibernate.connection.password" value="***" />

             

                                    <!-- Added to avoid NPE's on jboss! -->

                                    <property name="hibernate.query.jpaql_strict_compliance" value="false" />

             

                                    <!-- JDBC connection pool (use the built-in) -->

                                    <!-- <property name="hibernate.connection.pool_size" value="1" />  -->

                                    <!-- JDBC connection pool (use c3p0) -->

                                    <property name="hibernate.c3p0.min_size" value="5" />

                                    <property name="hibernate.c3p0.max_size" value="10" />

                                    <!-- Max time a connection idles (4 hours) -->

                                    <property name="hibernate.c3p0.timeout" value="14400" />

                                    <property name="hibernate.c3p0.max_statements" value="300" />

                                    <!-- Test idle connections every two hours -->

                                    <property name="hibernate.c3p0.idleTestPeriod" value="7200" />

             

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

             

                                    <!-- Enable Hibernate's automatic session context management-->

                                    <property name="hibernate.current_session_context_class"

                                            value="thread" />

                                    <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />

                                    <!-- Disable the second-level cache -->

                                    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />

             

                            </properties>

             

                    </persistence-unit>

             

            My server.log is in attachment.

             

            Thanks!!

            • 3. Re: migrated war deployed in as7 but no working annotationbinding
              prasad.deshpande

              name of the file should be persistence.xml, having said that, your listed jpa-persistence.xml has PU name as straininfo2-xenneke and log is reading

               

              15:59:41,451 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-4) Processing PersistenceUnitInfo [

                  name: straininfo2-test-xenneke

                  ...]

               

              does that mean you have persistence.xml in some other jar file in WEB-INF/lib or WEB-INF/classes?

               

              Also, if Jboss is providing JPA to your application then your log should have an entry like

              [org.jboss.jpa] (MSC service thread 1-1) : Read persistence.xml for straininfo2-test-xenneke

              but I couldn't see any such. Also does your classes has @Entity annotation (javax.persistence.Entity) on it otherwise it makes sense why it's asking for <class> tags?

               

              Also, could you please try with 7.1 Beta1 release of Jboss to see if you have same problem?

              • 4. Re: migrated war deployed in as7 but no working annotationbinding
                kwaegema

                I first had persistence.xml, I didn't work. Then I got this renaming from : http://community.jboss.org/blogs/mariusb/2011/07/13/spring-and-jboss-as7-part-1-getting-started     section 'spring travel'. But no changes..

                 

                I got 4 persistence units, i accidentally copied another, but it is the same (just -test- is with mor logging enabled).

                 

                my persistence is indeed in another jar file in WEB-INF/lib: the main war is the web-application and the core (persistence, entity classes, dao , logic) is in that jar.

                 

                My classes have @Entities.

                 

                I tried now with 7.1.Beta1. Because 7.1 had an error because multiple PU's were in my persistence.xml, I changed it (temporary) to only one PU:

                 

                <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">

                 

                 

                        <!-- Configuratie van de persistence units. -->

                 

                 

                                <persistence-unit name="straininfo2-test-xenneke">

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

                                <properties>

                 

                 

                 

                 

                                        <property name="hibernate.archive.autodetection" value="class"/>

                                        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />

                                        <property name="hibernate.connection.url"

                                                value="jdbc:oracle:thin:@***:1521:***" />

                 

                 

                                        <property name="hibernate.connection.username" value="***" />

                                        <property name="hibernate.connection.password" value="***" />

                 

                 

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

                 

                 

                                        <!-- Echo all executed SQL to stdout -->

                                        <property name="hibernate.show_sql" value="true" />

                                        <property name="hibernate.format_sql" value="true" />

                 

                                        <!-- Added to avoid NPE's on jboss! -->

                                        <property name="hibernate.query.jpaql_strict_compliance" value="false" />

                                        <!-- JDBC connection pool (use the built-in) -->

                                        <!-- <property name="hibernate.connection.pool_size" value="1" />  -->

                                        <!-- JDBC connection pool (use c3p0) -->

                                        <property name="hibernate.c3p0.min_size" value="3" />

                                        <property name="hibernate.c3p0.max_size" value="5" />

                                        <property name="hibernate.c3p0.timeout" value="900" />

                                        <property name="hibernate.c3p0.max_statements" value="300" />

                                        <!-- Test idle connections every two hours -->

                                        <property name="hibernate.c3p0.idleTestPeriod" value="7200" />

                 

                 

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

                                        <!-- Enable Hibernate's automatic session context management-->

                                        <property name="hibernate.current_session_context_class"

                                                value="thread" />

                                        <!-- Disable the second-level cache -->

                                        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />

                                        <property name="jboss.as.jpa.providerModule" value="hibernate3-bundled" />

                                </properties>

                        </persistence-unit>

                 

                 

                </persistence>

                I also changed the name back to persistence.xml.

                 

                I have the server.log in attachment.

                Now that persistence.xml is back in place, I see again two times the processing PersistenceUnit:

                 

                10:30:53,993 INFO  [org.jboss.jpa] (MSC service thread 1-4) JBAS011401: Read persistence.xml for straininfo2-test-xenneke

                10:30:56,215 INFO  [org.jboss.jpa] (MSC service thread 1-10) JBAS011402: Starting Persistence Unit Service 'ROOT.war#straininfo2-test-xenneke'

                10:30:56,358 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-10) Processing PersistenceUnitInfo [

                          name: straininfo2-test-xenneke

                          ...]

                ...

                ...

                ...

                10:30:59,979 INFO  [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (MSC service thread 1-3) Building JPA container EntityManagerFactory for persistence unit 'straininfo2-test-xenneke'

                10:30:59,979 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-3) Processing PersistenceUnitInfo [

                          name: straininfo2-test-xenneke

                          ...]

                 

                The first does some annotation binding (with some missing packets) but the second doesn't..

                 

                Thanks!!

                • 5. Re: migrated war deployed in as7 but no working annotationbinding
                  prasad.deshpande

                  kwaegema wrote:

                   

                  my persistence is indeed in another jar file in WEB-INF/lib: the main war is the web-application and the core (persistence, entity classes, dao , logic) is in that jar.

                   

                  My classes have @Entities.

                  Generally, I've observed for Jboss JPA, the jar file that contains persistence.xml only will be scanned for @Entity annotation. So if you have few entities in another separate jar, that jar will not be looked/scanned for classes containig @Entity annotation. This might be true in your case.

                   

                   

                  Now that persistence.xml is back in place, I see again two times the processing PersistenceUnit:

                   

                  10:30:53,993 INFO  [org.jboss.jpa] (MSC service thread 1-4) JBAS011401: Read persistence.xml for straininfo2-test-xenneke

                  10:30:56,215 INFO  [org.jboss.jpa] (MSC service thread 1-10) JBAS011402: Starting Persistence Unit Service 'ROOT.war#straininfo2-test-xenneke'

                  10:30:56,358 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-10) Processing PersistenceUnitInfo [

                            name: straininfo2-test-xenneke

                            ...]

                  ...

                  ...

                  ...

                  10:30:59,979 INFO  [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] (MSC service thread 1-3) Building JPA container EntityManagerFactory for persistence unit 'straininfo2-test-xenneke'

                  10:30:59,979 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-3) Processing PersistenceUnitInfo [

                            name: straininfo2-test-xenneke

                            ...]

                   

                  The first does some annotation binding (with some missing packets) but the second doesn't..

                   

                  seems that Jboss & spring both are kicking-in for processing PU. I'm not sure about how spring does it so my help on spring will be limited. It seems to me that spring JPA is not scanning entities however, Jboss JPA is scanning see the following logs..

                   

                  10:30:56,574 INFO  [org.hibernate.cfg.AnnotationBinder] (MSC service thread 1-10) Binding entity from annotated class: net.straininfo2.entities.Field

                  10:30:56,600 INFO  [org.hibernate.cfg.annotations.EntityBinder] (MSC service thread 1-10) Bind entity net.straininfo2.entities.Field on table si2.fields

                   

                  May be you want to try Jboss JPA or play around with spring one..

                  1 of 1 people found this helpful
                  • 6. Re: migrated war deployed in as7 but no working annotationbinding
                    kwaegema

                    all my entities are in the same jar

                     

                    I think indeed both Jboss and spring are processing PU.

                    I would like to use Spring because then the same war can be used on local Jetty webservers (for development).

                     

                    I started over once again with this guide (https://docs.jboss.org/author/display/AS7/Spring+applications+development+and+migration+guide)

                    And thus changing back to jpa-persistence so that Jboss stops processing PU. Now there's only the second processing (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) but still no scanning entities..

                    Because it worked this way with Jetty and Jboss 4, I'm still convinced its a problem between Jboss and Spring/Hibernate..

                     

                    I will ask a new question with clear notice that it is a spring-jboss problem..

                     

                    Thanks for helping me find the problem!