Issue Details (XML | Word | Printable)

Key: SPR-2623
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Scott Haug
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

FlushMode.NEVER deprecated in Hibernate 3.2 in favor of FlushMode.MANUAL

Created: 21/Sep/06 06:37 PM   Updated: 22/Sep/06 04:34 AM   Resolved: 22/Sep/06 04:34 AM
Component/s: None
Affects Version/s: 2.0 RC4
Fix Version/s: 2.0 final

Time Tracking:
Not Specified


 Description  « Hide

Hibernate 3.2 (as of CR3) has deprecated FlushMode.NEVER in favor of FlushMode.MANUAL. It seems it is purely a renaming (i.e., they have the same level of 0), but both still exist and they're distinct objects. Thus, using FlushMode.MANUAL in favor of FlushMode.NEVER will cause unexpected behavior in many hibernate-related Spring classes, which still are only checking for FlushMode.NEVER. The classes where this could be a problem include:

org.springframework.orm.hibernate3

  • HibernateAccessor
  • HibernateTemplate
  • HibernateTransactionManager
  • SessionFactoryUtils
  • SpringSessionSynchronization
    org.springframework.orm.hibernate3.support
  • OpenSessionInViewFilter

For example, our app, which makes heavy use of both Spring and Hibernate, recently started using Spring 2.0 cr4 and Hibernate 3.2 cr4. When I replaced all occurrences of FlushMode.NEVER with FlushMode.MANUAL in our project, we ended up not having any actions to commit when the transaction closed, but there were still unflushed actions when the session closed. We were using a subclass of OpenSessionInView, which was allowed for configuring a different FlushMode, so this may be the source of the issue. At any rate, switching all instances of FlushMode.MANUAL back to NEVER fixed the problem.

It seems the Spring support classes should check for both.



Juergen Hoeller added a comment - 22/Sep/06 04:34 AM

Thanks for pointing this out! It's indeed a bit of a pain to have to deal with two distinct FlushMode instances there...

Anyway, I've changed all our "equals(FlushMode.NEVER)" checks to use "FlushMode.lessThan(FlushMode.COMMIT)" instead, which should catch both NEVER and MANUAL. Furthermore, this "lessThan" check should also work on Hibernate 3.0, which we still aim to be compatible with (as far as possible; mainly for JDK 1.3 users, who won't be happy with Hibernate 3.1 and later requiring JDK 1.4+). For the latter reason, it's also that our "setFlushMode(FlushMode.NEVER)" calls have to remain the same, even if NEVER is deprecated now: "FlushMode.MANUAL" simply won't work on Hibernate 3.0/3.1. That said, this present refined code should work fine for typical needs...

Juergen