-->
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.  [ 8 posts ] 
Author Message
 Post subject: Tapestry + Hibernate issue (or just general web app issue)
PostPosted: Wed Jan 11, 2006 9:08 pm 
Beginner
Beginner

Joined: Thu Sep 22, 2005 7:22 am
Posts: 21
Hibernate version: 3.1
Tapestry version: 4.0

Hi all!

Tapestry+Hibernate problem ahead...

I want to have a form that allows me to alter a certian object. the
form should use validation, so if something goes wrong I want to be
able to correct the mistake and be able to press save again. I don`t
want the changes to persist until the validation succeeds.

When the page gets attached I load the object O by calling
MyDAO.getMyObject(..);
this method is intercepted and a transaction is wrapped around the call.

After this (if save was pressed), Tapestry gets all POST data and
updates O with the new values.
Note that the altering of O is done outside a transaction! I know that
this is not good, but the alternative would be to wrap it in a
transaction, and thus commiting the changes.. which I don`t want to do
until I have done the final validation in my listener (the one listening on the save button). Then and only
then I want to explicitly persist the changes.

I guess that working with the same object over different transactions
is considered a bad thing.. but how should it be done otherwise?

One thought I had was to set O on a Tapestry persisted method (using
@Persist) the first time I get to the page. and then work with that
and finally when I want to persist the object attach it to the session
(using session.lock(...)) and then session.merge(...);

Another though was to let the transaction span over the whole request/response but that will result in unwanted persisting of data.. (remember the POST data tapestry automatically update the O with)

Everything else works just fine. I use HibernateSqueezer (tapestry thing) which works
brilliant. and I intercept all my DAO:s methods. the persistent layer
is _almost_ transparent... it`s just this little "update problem"
that`s still bugging me..

Thanks!

_________________
/ted


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 6:44 am 
Beginner
Beginner

Joined: Thu Sep 22, 2005 7:22 am
Posts: 21
bump...

_________________
/ted


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 7:21 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Validate input before to populate properties.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 12:37 pm 
Newbie

Joined: Tue Nov 15, 2005 4:21 am
Posts: 11
Tapestry will automatically modify the properties of your object, but if you determine in your listener that the changes should not be allowed, you can rollback the transaction and no changes will be persisted to the database.


Top
 Profile  
 
 Post subject: Re: Tapestry + Hibernate issue (or just general web app issu
PostPosted: Thu Mar 16, 2006 10:03 pm 
Beginner
Beginner

Joined: Fri May 06, 2005 2:37 pm
Posts: 39
websheriff wrote:
Hibernate version: 3.1
Tapestry version: 4.0

After this (if save was pressed), Tapestry gets all POST data and
updates O with the new values.
Note that the altering of O is done outside a transaction! I know that
this is not good, but the alternative would be to wrap it in a
transaction, and thus commiting the changes.. which I don`t want to do
until I have done the final validation in my listener (the one listening on the save button). Then and only
then I want to explicitly persist the changes.


Surprised there's been no response here.

My question is the similar: if I change an object outside of a session, then open and commit a transaction, will my changes be persisted?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 2:58 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
See Session.merge()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 2:43 pm 
Beginner
Beginner

Joined: Fri May 06, 2005 2:37 pm
Posts: 39
baliukas wrote:
See Session.merge()


Thanks, but I was more curious about the theory than solving the problem. :-)

Given this example:

A a = [load A from database]
a.setBlah("b");

tx = beginTransaction();
tx.close();

(so A is attached, but changes are made outside the transaction)

What exactly happens to the data change on A? I assume it gets flushed on transaction close, although the data change was outside the transaction scope.

Also, are there fundamental differences for Hibernate between changing A inside and outside the transaction?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 18, 2006 12:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If you make a change to the object while in session then it will be marked dirty and automatically update otherwise nothing will be stored unless you expicitly use session.update or session.merge on the data.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.