Results 1 to 8 of 8

Thread: Hibernate unwanted flush() from TransactionInterceptor

  1. #1
    Join Date
    Mar 2008
    Posts
    6

    Default Hibernate unwanted flush() from TransactionInterceptor

    Hi,

    I'm currently using Spring and Hibernate in the following configuration:

    Spring: 2.0.6
    Hibernate: 3.2
    Transaction management: Declarative with annotations (@Transactional)
    I also use the Spring OpenSessionInViewFilter.
    Finnaly, my transactions are configured with the following XML:

    <bean id="txManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="fwksessionFactory"/>
    </bean>

    <tx:annotation-driven transaction-manager="txManager"/>

    My problem is that every time I do any kind of data access operation such as session.get(...), the hibernate session is flushed, which is causing an early commit whenever the session is dirty.

    Using a debugger, I am able to see that TransactionInterceptor.commitTransactionAfterRetur ning(TransactionInfo txInfo) is being called when I use session.get(...)

    I'm not sure what code to post. Imagine any code that calls session.get() for any reason!

    Please help if you can,

    -Paul

  2. #2

    Default

    I think you don't have configured properly your transaction interceptor
    There are two ways of spreading the light ... Be the lamp that emits, or the mirror that reflects it

  3. #3
    Join Date
    Mar 2008
    Posts
    6

    Default

    Quote Originally Posted by guillermodl View Post
    I think you don't have configured properly your transaction interceptor
    Can you be more specific? The xml I posted is all the configuration i have got, plus the annotations of course.

    If I don't use any data access methods then I can see that the transactional behaviour is correct in methods annotated with @Transactional. It's only when I load any other data as part of a transaction that my session is flushed.

  4. #4

    Default

    PHP Code:
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
             <!-- 
    the transactional semantics... -->
             <
    tx:attributes>
                 <!-- 
    all methods starting with 'get' are read-only -->
                 <
    tx:method name="get*" read-only="true" />
                 <
    tx:method name="find*" propagation="REQUIRED" read-only="true" />
                 <
    tx:method name="load*" propagation="REQUIRED" read-only="true" />
                 <
    tx:method name="store*" propagation="REQUIRED" />
                 <
    tx:method name="delete*" propagation="REQUIRED" />
                 <
    tx:method name="*" />
             </
    tx:attributes>
         </
    tx:advice>

         <!-- 
    ensure that the above transactional advice runs for any execution
             of an operation defined by the FooService 
    interface -->
         <!--  
    filtra las interfaces del paquete de servicio -->
         <!--  
    el avisa al txAdvice que corresponde a la ejecucion de generalServiceOperation -->
         <
    aop:config>
            <
    aop:pointcut id="generalServiceOperation" expression="execution(* org.myesample.service.*.*(..))"/>    
            <
    aop:advisor advice-ref="txAdvice" pointcut-ref="generalServiceOperation"/>
        </
    aop:config
    There are two ways of spreading the light ... Be the lamp that emits, or the mirror that reflects it

  5. #5
    Join Date
    Mar 2008
    Posts
    6

    Default

    Thanks for your help, but I would really rather use java Annotations to manage transactions. Can anyone help me with that?

  6. #6
    Join Date
    Mar 2008
    Posts
    6

    Default

    I think I can prove that my xml configuration is not wrong. Firstly, if I take out the configuration, all my transactions fail because the OpenSessionInViewFilter is expecting a transaction manager.

    Secondly, in a transaction that doesn't require any reads, I get a proper rollback when exceptions are thrown.

    Has anyone experianced a similar problem to this?

  7. #7
    Join Date
    Mar 2008
    Posts
    170

    Default

    Hi all,

    I have a similar/same issue in combination with Spring Webflow and opened a thread http://forum.springframework.org/sho...232#post190232.

    Could be interesting for reader of this thread.

    - Peter

  8. #8
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    1. ow your methods are annotated (do you annotate simply by @Transactional or you specify as well some attributes for this annotation)?
    2. flush by itself does not induce commit. Are you sure that hibernate not only flushes but as well commits session.
    3. there are situations where Hibernate makes flushes on its own (depending on configuration), e.g. in cases of queries that may touch dirty objects. Are you sure that it is not your situation?


    Regards,
    Oleksandr

    Quote Originally Posted by Irons UK View Post
    Thanks for your help, but I would really rather use java Annotations to manage transactions. Can anyone help me with that?

Posting Permissions

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