-->
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.  [ 5 posts ] 
Author Message
 Post subject: More lazy load problems, POST redirect to GET
PostPosted: Fri Sep 03, 2004 4:28 am 
Newbie

Joined: Sun Oct 12, 2003 4:21 pm
Posts: 16
Location: Stockholm, Sweden
Hibernate version: 2.1.6

My web application changes model state in a POST request, then redirects to a .jsp for view rendering which results in a GET request.
The problem is that I have implemented the "one Hibernate session per HTTP request" pattern, and I get two requests, a POST followed by a GET. The view (GET) cannot lazy load collections since the model was loaded in the previous POST request.
I tried to open the session in the beginning of the POST request and then close the session in the end of the GET request, but it get ugly when exceptions occur, etc.
What it best practise here? I dont want to replace the POST-redirect-GET pattern. And I don't want to keep an open hibernate session in the http session. Should I keep a list of all top objects loaded by POST and reconnect them in the GET? That sounds complicated too.
I'm clueless...
/Goran


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 4:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you can use session-per-application-transaction pattern, if you like


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 5:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i may have missed something about session-per-application-transaction pattern

let's take a concrete example:

----------Application Transaction-------------
------------Hibernate Session-----------------
---- R1----|-----R2------|------R3-------------
---- T1----|-----T2------|------T3-------------


where R1,R2 et R3 are httpRequests and T1,T2,T3 are underlying db transaction.
Between each httpRequest, we have a session.disconnect().
R1 --> select object (+detache object to send to jsp)
R2 --> reattach object + updates (if session.update() is called, version is incremented), what may we do here commit or rollback (i don't want to commi the application transaction)
R3 --> some other updates + validation per user to say "ok go for commit" (i want the application transaction to be comitted)

We must finish the db transactions (if not, we're going into db lock if we updated something in the session), to do it two choices:
- commit, and so our application transaction have no sense, the transaction aspect is lost
- rollback, and with it session has stale data in case of versionning for example

Is the solution to set flushMode=commit ?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 04, 2004 2:06 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Collect user input in this "application transaction" without any data access( this step is not related to hibernate ), insert this data to DB at last step in single transaction (it must be better not to use "update/delete" for this kind of use cases, create new record and maintain some version attribute). I did a lot of web applications and I heve never saw problems with "long transactions". I found a good way is to sore "application transaction" state on client (hidden form fields) it will help for stuff like clustering.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 04, 2004 3:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i totally agree with you baliukas,
so we can tell that for this:

----------Application Transaction-------------
------------Hibernate Session-----------------
---- R1----|-----R2------|------R3-------------
---- T1----|-----T2------|------T3-------------

R1: read
R2: update detached object and keep them out of the hibernate session scope (no reattach)
R3: reattach detached object and persist changes

Thanks!

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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

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.