Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Jencks, Hibernate, Geronimo and Spring 2.0.6 -> 2.5.2 upgrade problem

  1. #1
    Join Date
    Dec 2006
    Posts
    19

    Default Jencks, Hibernate, Geronimo and Spring 2.0.6 -> 2.5.2 upgrade problem

    Hi,

    I am trying to upgrade to spring 2.5.2 with the above mentioned packages in use. Code that used to work throws the follow exception with 2.5.2.

    Code:
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
           at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
           at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
           at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
           at javax.naming.InitialContext.lookup(InitialContext.java:351)
           at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
           at org.hibernate.transaction.JTATransactionFactory.createTransaction(JTATransactionFactory.java:53)
           at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:177)
           at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1279)
           at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78)
           at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:508)
    I have noticed the following, but doubt that it is why this is happening. It seems that in 2.0.6 SessionFactoryImpl was fronted with a proxy. When getCurrentSession was called the proxy instead invoked a method on SessionFactoryUtils. This specific code was located in TransactionAwareInvocationHandler. In 2.5.2 SessionFactoryImpl is not fronted by a proxy and is called directly.

    I would like to know, out of interest, why / how it changed.

    But my actual question is , can anybody shed some light on why I am getting this exception in 2.5.2, is there something that I need to change or do differently?

    any help appreciated.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    As of Spring 2.5 a proxy isn't needed anymore. Hibernate provides hooks to retrieve the current session.

    Judging by your stacktrace you misconfigured you LocalSessionFactoryBean as judging from your stacktrace Hibernate is managing your transactions instead of Spring.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2006
    Posts
    19

    Default

    Thanks for your reply, I will check it out tomorrow.

    Can you maybe explain to me why the config would work with 2.0.6 and not with 2.5.2?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Due to the proxy. With the proxy each call to getCurrentSession() would be intercepted and redirected, regardless of the settings of hibernate. With the new approach it delegates to hibernate, so uses those settings.

    If you post your configuration we might figure out the issue.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Dec 2006
    Posts
    19

    Default

    Hi,

    Here is the config as requested. I must admit, I recently inherited the code, so I am still trying to make heads or tails of what it all means. Can you maybe point me to some reading material to understand how spring works with all this?

    Code:
      <bean id="connectionTracker"
            class="org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator"/>
    
      <bean id="baseConnectionManager" class="org.jencks.factory.ConnectionManagerFactoryBean" abstract="true">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="pooling" value="true"/>
        <property name="poolMinSize" value="5"/>
        <property name="poolMaxSize" value="100"/>
        <property name="connectionTracker" ref="connectionTracker"/>
      </bean>
    
      <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
        <property name="transactionLog">
          <bean class="org.apache.geronimo.transaction.log.UnrecoverableLog"/>
        </property>
        <property name="defaultTransactionTimeoutSeconds" value="3600"/>
      </bean>
    
      <alias name="transactionManager" alias="userTransaction"/>
    Hope this is what you need.

    Thanks for your help

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    The reference guide is a good start.

    However what I really wanted to see was your LocalSessionFactoryBean and it's configuration. That is missing from what you posted here.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Dec 2006
    Posts
    19

    Default

    We have extended the LocalSessionFactoryBean and configured it as below.

    Code:
      <bean id="hibernateSessionFactoryAbstract" class="net.devstream.commons.util.spring.EntityResolverLocalSessionFactoryBean" abstract="true">
        <property name="entityResolverClass" value="net.devstream.commons.util.hibernate.HibernateXMLFragmentClasspathEntityResolver"/>
        <property name="dataSource" ref="datasource"/>
        <property name="entityInterceptor" ref="hibernateInterceptor"/>
        <property name="hibernateConfigurationCreator" ref="hibernateConfigurationCreator"/>
        <property name="eventListeners">
          <map>
            <entry key="load">
              <bean class="net.devstream.commons.appframework.persistence.HibernateLoadEventListener"/>
            </entry>
          </map>
        </property>
        <property name="jtaTransactionManager" ref="transactionManager"/>
      </bean>
    The transactionManager is defined in above post.

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You extended it so there is additional stuff going on.

    Probably there is some custom ConfigurationCreator (no idea what that does?!), but probably generates some custom/additional configuration (which might screw things up).

    Next to that this bean is abstract so there must be another bean which has this bean as a parent..
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Dec 2006
    Posts
    19

    Default

    The hibernateConfigurationCreator implementation just calls
    Code:
    new Configuration();
    . We then set the entityResolver on the configuration, that is the only modification to the stock standard configuration.

    The beans that has the hibernateSessionFactoryAbstract bean as parent just sets the configLocation. Here is the configLocation file content for this specific scenario:
    Code:
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">net.devstream.commons.persistence.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
      </session-factory>
    
    </hibernate-configuration>
    The concrete sessionFactory is then injected into the hibernateTemplate.
    Last edited by driftwood; Mar 25th, 2008 at 03:22 AM.

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Wouldn't it be easier/better to override the 'postProcessConfiguration' method and then set the entityResolver? Saves you a class and creation of (another?) Configuration object.

    Well the culprit is in the configuration you showed. Remove the 'hibernate.current_session_context_class' and then it should work again.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •