Page 4 of 4 FirstFirst ... 234
Results 31 to 40 of 40

Thread: Spring+Hibernate: connection not closed

  1. #31
    Join Date
    Dec 2006
    Posts
    23

    Default

    Quote Originally Posted by dejanp View Post
    You are not updating anything, that's the problem. The session is opened and closed in the first line, and the changes you do with setters are done only in memory.

    Anyway, what is the point of changing spring/hibernate version for you? Hibernate 3 changed a lot of things and not everything works as it used to. On the other hand you seem very inpatient at making it work again.
    I did not decide to change those versions. Now I have to manage with a connection that is not closed. I think, even if H3 changed a lot of things, my problem is not normal.
    Sorry for being impatient. Actually, the application should be in production soon (at the end of the week). I have not a lot of time and I am getting mad as I w ork on it since 3 days.

    My test should throw a RuntimeException that leads to a rollback and close the connection. I know that lots of thing has changed in H3 but what I do not understand is why is it so hard to close my connection properly .

    Maybe, could you send me an example that works and I will try it.

    Thanks a lot for your help.

  2. #32
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    You are using JTA, Spring and Hibernate in a generally strange way. You bind JTA transaction management directly to Hibernate, but not to Spring, but on the other hand you expect Spring to manage Hibernate sessions for you. That's not how it's supposed to work and if it worked with S1/H2 it was more or less per accident.

    You should make Spring JTA aware and let it handle Hibernate end on it's own, or not use Spring HibernateTemplate at all and use pure Hibernate/JTA. Both are pretty well documented.

  3. #33
    Join Date
    Dec 2006
    Posts
    23

    Default

    Quote Originally Posted by dejanp View Post
    You are using JTA, Spring and Hibernate in a generally strange way. You bind JTA transaction management directly to Hibernate, but not to Spring, but on the other hand you expect Spring to manage Hibernate sessions for you. That's not how it's supposed to work and if it worked with S1/H2 it was more or less per accident.

    You should make Spring JTA aware and let it handle Hibernate end on it's own, or not use Spring HibernateTemplate at all and use pure Hibernate/JTA. Both are pretty well documented.
    How do I make Spring JTA aware? I still want to use CMT SLSB with Spring and Hibernate.

    Do you have a simply example?

  4. #34
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Just found this thread. Maybe it might be helpful.

    Regards,
    Andreas

  5. #35
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Quote Originally Posted by david.chau View Post
    How do I make Spring JTA aware? I still want to use CMT SLSB with Spring and Hibernate.

    Do you have a simply example?
    Setting the jtaTransactionManager in LocalSessionFactoryBean would be a nice start I guess.

  6. #36
    Join Date
    Dec 2006
    Posts
    23

    Default

    I did
    [CODE] <bean id="txManager"
    class="org.springframework.transaction.jta.JtaTran sactionManager"/>[/QUOTE]

    and
    Code:
      <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
        	<value>com/test/dao/hibernate/hibernate.hbm.xml</value>
        </property>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
          </props>
        </property>
        <property name="jtaTransactionManager" ref="txManager"/>
      </bean>
    I have this exception:
    Code:
    PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Fail
    ed to convert property value of type [org.springframework.transaction.jta.JtaTra
    nsactionManager] to required type [javax.transaction.TransactionManager] for pro
    perty 'jtaTransactionManager'; nested exception is java.lang.IllegalArgumentExce
    ption: No matching editors or conversion strategy found
    How do I set the jtaTransactionManager et which one?

  7. #37
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Sprign JtaTransactionManager doesn't implement javax.transaction.TransactionManager but encapsulates it. You need to look up your app server transaction manager through jndi and inject it. Spring JtaTransactionManager is not used at all and I'd say you can delete the definition.

  8. #38
    Join Date
    Dec 2006
    Posts
    23

    Default

    Hello,
    Finally, we found the issue of our problem.
    JOTM had a bug that is resolved in the HEAD version.
    JOnAS Packages an anterior version.

    Thanks for your help

  9. #39
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    So it's all working? With the latest Spring and Hibernate? Out of interest, if you are running Hibernate3, what did you do about the lazy initialization problems. Set lazy=false to revert to Hibernate2 behaviour. The only reason I ask, is that someone asked me about an upgrade recently. I would be interested to know how you tackled it.

  10. #40
    Join Date
    Dec 2006
    Posts
    23

    Default

    I use my initial configuration.
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <!DOCTYPE beans PUBLIC
            "-//SPRING//DTD BEAN//EN"
            "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
      <!-- =============== Data Sources =============== -->
      <bean id="dataSource"
            class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
          <value>jdbc/test</value>
        </property>
      </bean>
    
      <!-- =============== Transaction Manager =============== -->
    
      <!-- JTA Transaction Manager (Application server-provided) -->
      <bean id="txManager" 
            class="org.springframework.transaction.jta.JtaTransactionManager"/>
        
      <!-- =============== Hibernate Session Factories =============== -->
    
      <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
        	<value>com/test/dao/hibernate/hibernate.hbm.xml</value>
        </property>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">
              org.hibernate.dialect.Oracle9Dialect
            </prop>
            <prop key="hibernate.connection.provider_class">
              org.hibernate.connection.DatasourceConnectionProvider
            </prop>
            <prop key="hibernate.transaction.factory_class">
              org.hibernate.transaction.JTATransactionFactory
            </prop>
            <prop key="hibernate.transaction.manager_lookup_class">
              org.hibernate.transaction.JOTMTransactionManagerLookup
    	</prop>
    
            <prop key="hibernate.cache.region_prefix">test</prop>
            <prop key="hibernate.cache.use_minimal_puts">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.provider_class">
              org.hibernate.cache.EhCacheProvider
    	</prop>
          </props>
        </property>
      </bean>
    
    
      <!-- Reference Hibernate DAO -->
      <bean id="testDao"
            class="com.test.dao.hibernate.TestDaoHibernate">
        <property name="sessionFactory" ref="sessionFactory"/>
      </bean>
      
      <!-- RefService service object -->
      <bean id="testServiceImpl"
         class="com.test.service.TestServiceImpl">
        <property name="dao" ref="testDao"/>
        </property>
      </bean>
      
      <!-- Proxy for ReferenceService SLSB -->
      <bean id="testService"
     class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
        <property name="jndiName">
          <!-- Warning: JOnAS 3.3.x adds an '_L' suffix to the JNDI name of
            -  local beans
           -->
          <value>testService_L</value>
        </property>
        <property name="businessInterface">
          <value>com.test.TestService</value>
        </property>
      </bean>
    
    </beans>

Posting Permissions

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