-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Long Conversation
PostPosted: Wed Mar 26, 2008 9:03 am 
Newbie

Joined: Mon Feb 04, 2008 7:42 am
Posts: 7
Hibernate version: 3.2.5

Name and version of the database you are using:Oracle

I am developing a tomcat servlet database admin tool using hibernate. It must allow the user to be able edit, insert, delete records over a period of servlet requests. I.e. search for a record, edit it, search for something else etc etc... It must also allow the user to be able to commit/rollback when he or she chooses.

The most relevent documentation I have found is "the extended Session pattern for long Conversations" found here:
http://www.hibernate.org/43.html#A5
However this appears to commit the transaction after every request which is not what I am looking to do.

The setup I have at the moment is as follows:

    Hibernate config sets current_session_context_class to managed:
    Code:
        <property name="current_session_context_class">managed</property>

    Store a reference to the Hibernate Session in the HTTP Session.
    Before processing a servlet request reload the session and bind:
    Code:
            if (session == null) {
                session = sf.openSession();
                session.setFlushMode(FlushMode.MANUAL);
                ManagedSessionContext.bind(session);
                session.beginTransaction();

            } else {
                ManagedSessionContext.bind(session);
            }

    After processing a servlet request unbind:
    Code:
    session = ManagedSessionContext.unbind(sf);

    If the user chooses to commit:
    Code:
            session = ManagedSessionContext.unbind(sf);
            session.flush();
            session.getTransaction().commit();
            session = null;

    If the user chooses to rollback:
    Code:
            session = ManagedSessionContext.unbind(sf);
            session.flush();
            session.getTransaction().rollback();
            session = null;


This setup appears to be working as expected but it was more a result of hacking it together than really knowing what I was doing! Can anyone see any flaws in the setup?

Cheers in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.