Announcement Announcement Module
Collapse
No announcement yet.
Context loading problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context loading problem

    Hey everybody,

    I try to run a SpringMVC application with Hibernate and JPA...but following erreor occurs:

    Code:
    ...
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3f96ee: defining beans [dataSource,entityManagerFactory,transactionManager,org.springframework.context.weaving.AspectJWeavingEnabler#0,loadTimeWeaver,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0]; root of factory hierarchy
    [TomcatWeavingInsightClassLoader@8ab708] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3f96ee: defining beans [dataSource,entityManagerFactory,transactionManager,org.springframework.context.weaving.AspectJWeavingEnabler#0,loadTimeWeaver,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0]; root of factory hierarchy
    ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    ...
    My configuration looks like this:

    Code:
    ...
    <!-- Root Context: defines shared resources visible to all other web components -->
    	
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
            <property name="url" value="jdbc:hsqldb:mem:blog" />
            <property name="username" value="sa" />
            <property name="password" value="" />
        </bean>
     
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="persistenceUnitName" value="blogPU" />
            <property name="loadTimeWeaver" ref="loadTimeWeaver" />
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="showSql" value="false" />
                    <property name="generateDdl" value="true" />
                </bean>
            </property>
        </bean>
        
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
        
        <context:load-time-weaver />
        <tx:annotation-driven />
    ...
    So, whats wrong here?? I'm a beginner and can't figure out the problem, so I would be very grateful...:-)

  • #2
    What do you need

    <context:load-time-weaver />

    for?

    Do you not have interfaces on your classes or something?

    Also, I haven't used org.springframework.jdbc.datasource.DriverManagerD ataSource

    but have used BasicDataSource from that package. or used a vendors specific DataSource class. Not that it should make any difference.

    Finally, more important

    Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.orm.jpa.persistenceunit.Spring PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

    I am wondering if you have your peristence.xml file created with the bare minimum of creating the persistence unit named blogPU

    Mark

    Comment


    • #3
      Hey Mark,

      you're right, the load time weaver isn't necessary...

      I have a persistence.xml in my META-INF folder, but it doesn't work either.

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <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="blogPU">
          </persistence-unit>
      </persistence>
      Thank you anyhow...Any other ideas??

      Markus

      Comment


      • #4
        And you also removed

        <property name="loadTimeWeaver" ref="loadTimeWeaver" />

        in the EntityManager bean definition?

        the META-INF directory is in the root of your classpath, correct? Just a precaution question, I am already assuming it is.

        Mark

        Comment


        • #5
          Hmm,
          I don't really have any EntityManager bean definition yet...I was modelling some entities and before creating some tests, I wrote the code above to setup the persistence environment. Then I ran the application by accident and instead the "Hello World" from MVC, I got the error...

          I would inject the EntityManager via @PersistenceContext, or am I totally wrong??

          Comment


          • #6
            Hmm,
            I don't really have any EntityManager bean definition yet...I was modelling some entities and before creating some tests, I wrote the code above to setup the persistence environment. Then I ran the application by accident and instead the "Hello World" from MVC, I got the error...

            Where do have to put my persitence.xml in STS? I get it in src/main/ressources/META-INF...Choosing another location, raises an error that bookPU cand be found, so it must be right...

            Comment


            • #7
              If you look at the context of my post you can see I meant your factory.

              Mark

              Comment


              • #8
                Yeah, I know, sorry...

                Comment


                • #9
                  What version of Spring and Hibernate are you using?

                  I found this bug

                  https://jira.springsource.org/browse/SPR-6705

                  and I found this

                  http://stackoverflow.com/questions/3...1-with-jpa-2-0

                  So, Based on them, I am guessing there is a compatabilty issue here and all the crap I wrote meant nothing before.

                  Although I still don't think you need the load time weaver.

                  Mark

                  Comment


                  • #10
                    Got it!

                    I'm stupid...

                    Had spring-jpa, in addition to hibernate-entitymanager in my path...Without spring-jpa, it' works...

                    Thanks for your your efford, rock on!!

                    Markus

                    Comment

                    Working...
                    X