Announcement Announcement Module
Collapse
No announcement yet.
Problem with Spring2 RC4 and Hibernate JPA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Spring2 RC4 and Hibernate JPA

    Hello,

    I have a problem with Hibernate JPA and Spring RC4.
    All is Ok with Spring2 RC3.

    Error log
    [junit] Warning: Caught exception attempting to use SAX to load a SAX XMLReader
    [junit] Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser
    [junit] Warning: I will print the stack trace then carry on using the default SAX parser
    [junit] java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser
    [junit] at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unk nown Source)
    [junit] at org.xml.sax.helpers.XMLReaderFactory.createXMLRead er(Unknown Source)
    [junit] at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.j ava:83)
    [junit] at org.dom4j.io.SAXReader.createXMLReader(SAXReader.j ava:894)
    [junit] at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java :715)
    [junit] at org.dom4j.io.SAXReader.setFeature(SAXReader.java:2 18)
    [junit] at org.hibernate.ejb.Ejb3Configuration.addXMLEntities (Ejb3Configuration.java:372)

    <skipped>

    [junit] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Cannot resolve reference to bean 'txAdvice' while setting bean property 'advice'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
    [junit] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
    [junit] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'transactionManager' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
    [junit] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in file [D:\Workspace\OWBAudit\web\WEB-INF\ApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.ExceptionInInitializerError
    [junit] Caused by: java.lang.ExceptionInInitializerError
    [junit] at org.hibernate.util.ReflectHelper.<clinit>(ReflectH elper.java:23)

    <skipped>

  • #2
    God how I have longed for another person to have this problem!
    I reported the exact same error in here a couple of days ago. I also created a Jira for it.
    The *only* thing I did to my fully working application was to upgrade Spring from 2.0-RC3 to 2.0-RC4. When it failed after the upgrade I tried to upgrade Hibernate EM (and its dependicies) to 3.2 CR 2 (from 3.2 CR 1) but with no luck.
    If you look at the Jira, you can see that I managed to find out that the problem was introduced in the spring-framework-2.0-rc4-build.1-20060830.zip-snapshot. The last snapshot before that was spring-framework-2.0-rc4-build.120-20060822.zip and it worked just fine.

    Cheers,
    Peter

    Comment


    • #3
      Peter,

      There was a change in passing the root URL of the persistence unit to the persistence provider - see JIRA 2493

      Could you post your configuration and directory/jar setup.

      Comment


      • #4
        Originally posted by trisberg View Post
        Could you post your configuration and directory/jar setup.
        I sure can.

        Structure:
        -WEB-INF/applicationContext.xml
        -WEB-INF/classes/persistence_1_0.xsd
        -WEB-INF/classes/META-INF/persistence.xml
        -WEB-INF/classes/META-INF/orm.xml

        I use annotations for all my persistent objects and these are located in WEB-INF/classes.

        applicationContext.xml:
        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:tx="http://www.springframework.org/schema/tx"
               xmlns:aop="http://www.springframework.org/schema/aop"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
                                   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                                   http://www.springframework.org/schema/tx
                                   http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
                                   http://www.springframework.org/schema/aop
                                   http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
        
           <tx:annotation-driven />
        
           <bean id="abstractMgr" abstract="true">
              <property name="entityManagerFactory" ref="entityManagerFactory" />
           </bean>
        
           <bean id="userMgr" class="com.foo.bar.business.service.impl.UserMgrJpa" parent="abstractMgr" />
        
           <bean id="movieMgr" class="com.foo.bar.business.service.impl.MovieMgrJpa" parent="abstractMgr" />
        
           <!--<bean id="entityManagerFactory" class="org.springframework.orm.jpa.ContainerEntityManagerFactoryBean">-->
           <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
              <property name="dataSource" ref="dataSource" />
              <property name="jpaVendorAdapter">
                 <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database" value="HSQL" />
                    <property name="showSql" value="false" />
                    <property name="generateDdl" value="false" />
                 </bean>
              </property>
              <property name="loadTimeWeaver">
                 <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
              </property>
           </bean>
        
           <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
              <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
              <property name="url" value="jdbc:hsqldb:hsql://localhost:1717/xdb" />
              <property name="username" value="sa" />
              <property name="password" value="" />
           </bean>
        
           <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
              <property name="entityManagerFactory" ref="entityManagerFactory" />
              <property name="dataSource" ref="dataSource" />
           </bean>
        
        </beans>
        persistence.xml:
        Code:
        <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="Movies" transaction-type="RESOURCE_LOCAL">
           </persistence-unit>
        
        </persistence>
        orm.xml:
        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
            version="1.0">
        
        </entity-mappings>
        I've tested this with both Tomcat 5.5.17 (with org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader) and the maven-Jetty-plugin.

        Thanks,
        Peter

        Comment


        • #5
          I'd add the entity declarations to orm.xml - something like:

          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
              version="1.0">
          
              <package>com.foo.bar.business.domain</package>
              <entity class="User" metadata-complete="false" access="FIELD"/>
              <entity class="Movie" metadata-complete="false" access="FIELD"/>
          
          </entity-mappings>
          This might not solve this problem, but can't hurt.
          Last edited by trisberg; Sep 23rd, 2006, 12:33 PM.

          Comment


          • #6
            Originally posted by trisberg View Post
            I'd add the entity declarations to orm.xml - something like:

            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
                version="1.0">
            
                <package>com.foo.bar.business.domain</package>
                <entity class="User" metadata-complete="false" access="FIELD"/>
                <entity class="Movie" metadata-complete="false" access="FIELD"/>
            
            </entity-mappings>
            This might not solve this problem, but can't hurt.
            Unfortunately, it didn't solve my problem.
            Is it required to specify the entities in orm.xml when one use annotations?

            Comment


            • #7
              Is there really noone out there that has a clue what I'm doing wrong?

              Cheers,
              Peter

              Comment


              • #8
                After some extensive trial and error-testing I finally resolved it!
                applicationContext that produces the error:
                Code:
                   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                      <property name="dataSource" ref="dataSource" />
                      <property name="jpaVendorAdapter">
                         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                            <property name="database" value="HSQL" />
                            <property name="showSql" value="false" />
                            <property name="generateDdl" value="false" />
                         </bean>
                      </property>
                      <property name="loadTimeWeaver">
                         <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
                      </property>
                   </bean>
                If I remove
                Code:
                      <property name="loadTimeWeaver">
                         <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
                      </property>
                everything works. Weeeehaaah!

                Cheers,
                Peter

                Comment


                • #9
                  Thank you for this message.
                  I can't check this config myself right now.

                  BTW it seems that property loadTimeWeaver is mandatory for Tomcat deployment.

                  Have you test your application with Tomcat?

                  Comment


                  • #10
                    Originally posted by kolchanov View Post
                    BTW it seems that property loadTimeWeaver is mandatory for Tomcat deployment.
                    Have you test your application with Tomcat?
                    I just tested with Tomcat 5.5.17 and it worked for me without a LTW.
                    I have spring-tomcat-weaver.jar in server/lib but I don't have a LTW specified in "webapp"/WEB-INF/applicationContext.xml nor "webapp"/META-INF/context.xml

                    Cheers,
                    Peter

                    Comment


                    • #11
                      You don't need a loadtime weaver when you use Hibernate as the JPA persistence provider.

                      Comment


                      • #12
                        Originally posted by trisberg View Post
                        You don't need a loadtime weaver when you use Hibernate as the JPA persistence provider.
                        Exactly what I thought but I got nervous when kolchanov said I did.

                        Comment


                        • #13
                          Thank you!

                          Comment

                          Working...
                          X