Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Transaction trouble

  1. #11
    Join Date
    Dec 2005
    Posts
    8

    Default FlushMode.AUTO

    Somehow my FlushMode is being set to NEVER in my application. I have no idea where, I have greped, searched in my IDE, etc. I took Loren's advice and explicitly set the FlushMode to AUTO in all of my save methods. This fixed one of my 5 save methods, that one now persists to the database. The other save methods no longer throw the "Write operations are not allowed in read-only mode (FlushMode.NEVER)...", they appear to do the same thing as the save method that actually works but nothing is persisted to the database.

    Any ideas?

  2. #12
    Join Date
    Nov 2005
    Posts
    24

    Default

    I had problems with 7.3 . Don't remember the driver version , as i simply took the latest for my DB . You seem up to date so I guess no luck with findinig the problem there

  3. #13
    Join Date
    Dec 2005
    Location
    Washington DC
    Posts
    2

    Default This may help

    I was having the same problem with an Oracle db.

    InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session ...
    I believe the problem was caused by upgrading to the latest 3.1 Hibernate jar, but that's just a guess.

    I added flushMode property to openSessionInViewInterceptor everything seems to work.

    <bean name="openSessionInViewInterceptor"
    class="org.springframework.orm.hibernate3.support. OpenSessionInViewInterceptor">
    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    <property name="flushMode">
    <bean id="org.springframework.orm.hibernate3.HibernateAc cessor.FLUSH_AUTO" class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean"/>
    </property>
    </bean>
    I hope this helps.

  4. #14
    Join Date
    Dec 2005
    Posts
    8

    Default The same occurred when upgrading to 2.0 M1, Hibernate 3.1, using tx:advice

    I am also using OpenSessionInViewFilter. When I using the old transaction config
    method, every thing is OK. But when I converted the config to use the new tx:advice style, the same problem accurred.

    I have solved the problem with a customized OpenSessionInViewFilter implementation as the following code shows:

    public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter {
    protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(FlushMode.AUTO);
    return session;
    }

    protected void closeSession(Session session, SessionFactory sessionFactory) {
    session.flush();
    SessionFactoryUtils.releaseSession(session, sessionFactory);
    }
    }

  5. #15
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Can you please raise an issue on JIRA? Thanks.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #16
    Join Date
    Dec 2005
    Posts
    8

    Default OpenSessionInViewFilter

    xml2008, thanks so much for the post. I don't know why I didn't go directly to the srouce and the source documentation in the first place. It would have saved me lots of pain.

    From the documentation for OpenSessionInViewFilter:

    NOTE: This filter will by default not flush the Hibernate Session, as it assumes to be used in combination with service layer transactions that care for the flushing, or HibernateAccessors with flushMode FLUSH_EAGER. If you want this filter to flush after completed request processing, override closeSession and invoke flush on the Session before closing it. Additionally, you will also need to override getSession() to return a Session in a flush mode other than the default FlushMode.NEVER. Note that getSession and closeSession will just be invoked in single session mode!

    So in conclusion, Spring was setting the flush mode to NEVER!

    To fix my problem I did as the documentation suggests and as xml2008 suggested and over-rode the getSession() and closeSession() methods in OpenSessionInViewFilter.

    Thanks for all the help.

  7. #17
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    OSIV deliberately sets flush mode to NEVER - it should be used along with a TransactionManager. The problem is that using tx:advice does not trigger the flush.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  8. #18
    Join Date
    Dec 2005
    Posts
    8

    Default

    I am not using tx:advice. I am using declarative transactions with the HibernateTransactionManager and there is no flush triggered.

  9. #19

    Default

    This helped quite a bit... thanks
    Last edited by hasdy; Jan 18th, 2006 at 12:31 PM.

Posting Permissions

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