Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.0, Hibernate Factory & SchemaUpdate problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.0, Hibernate Factory & SchemaUpdate problem

    Hello! I just upgraded to Spring 2.0 and meet followed problem.

    I'm using Hibernate for database access. Session Factory defined by followed standard way:
    Code:
    <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource"></property>
      <property name="mappingLocations">
        <list>
          <value>xxx</value>
        </list>
      </property>
      <property name="hibernateProperties">
        <props>
          <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
          <prop key="hibernate.show_sql">false</prop>
          <prop key="hibernate.cache.use_second_level_cache">false</prop>
        </props>
      </property>
            
      <property name="schemaUpdate" value="true"/>
    </bean>
    Problem is that I've got error SessionFactory is not initialized during this bean initialization.

    After some debugging I found that this exception throws from AbstractSessionFactoryBean.getSessionFactory() method. Attribute sessionFactory (as I underastand from code) should be initialized in AbstractSessionFactoryBean.afterPropertiesSet() method. I run my application in debug mode and set breakpoints in both methods. And found that afterPropertiesSet() is not called.

    As I found, AbstractSessionFactoryBean.getSessionFactory() called from LocalSessionFactoryBean.updateDatabaseSchema() and seems, by some reasons this method is called before afterPropertiesSet() and as result - before session factory initialization.

    After commenting tag schemaUpdate application started to work.

    I do not know - is it bug in Spring 2.0 (before it I used RC3), or probably something wrong in my (quite complex) spring configuration, so, I didn't added this issue as bug.

    Can anybody check - does schema update works for hibernate in their Spring 2.0 based project? Thank you.

  • #2
    Can you post the stack trace as well?

    Comment


    • #3
      Stack Trace

      Yes, of course, looking more detail into stack trace I see it is a bug - afterPropertiesSet called buildSessionFactory and it's called updateDatabaseSchema - before sessionFactory is really created

      Seems it is real bug and I will report it into JIRA

      Code:
      SEVERE: Context initialization failed
      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in ServletContext resource [/WEB-INF/emforge-db.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: SessionFactory not initialized yet
      Caused by: java.lang.IllegalStateException: SessionFactory not initialized yet
      	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.getSessionFactory(AbstractSessionFactoryBean.java:175)
      	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.updateDatabaseSchema(LocalSessionFactoryBean.java:918)
      	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:762)
      	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
      	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
      	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
      	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
      	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
      	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
      	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4187)
      	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
      	at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
      	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
      	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
      	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
      	at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
      	at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:585)
      	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
      	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)

      Comment


      • #4
        Bugs in JIRA and already fixed

        OK, it is already in JIRA and fixed for version 2.0.1. Will wait for this version
        http://opensource.atlassian.com/proj...rowse/SPR-2669

        Comment

        Working...
        X