-->
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.  [ 3 posts ] 
Author Message
 Post subject: Need Help again
PostPosted: Mon Jun 26, 2006 10:31 am 
Newbie

Joined: Thu Jun 01, 2006 5:09 am
Posts: 16
Hi everybody, maybe I'm not using hibernate so good. I've this situation
using JSF
I have a form that refers to a "A" object.
Now I must reload page when the value of a combo changes. I made that in this way:

<h:selectOneMenu id="myvalues" valueChangeListener="#{backbean.myOnChange}" onchange="document.forms[0].submit();" value="#{backbean.value}">
<f:selectItems value="#{personeEditor.values}"/>
</h:selectOneMenu>

Of course I've lot of inputBoxes referred to "A" fields.
My problems is that when I reload page changing combo value, modifies to "A" object are saved to Database. I don't wanna that. I'd like to save my modify in a temp object and have that after reload but I want decide when to save them on DB (apply button).
Anybody could help me??

My Hibernate ver is 3.0
Bye


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 12:32 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
First, find out if transactions are for you. Even if things get saved to the DB, if it happens in a transaction you can still roll it back. This is the best solution, as transactions are common to all DB access libraries: the next solution is hibernate-specific.

If there's reasons you can't do that (e.g. there are other objects that you want to update in the same transaction), then you can detach your objects at any time by calling session.evict(obj). Assuming that the problem is that, in your action class, you're doing something like
Code:
A obj = (A) session.load(requestScope.getAttribute("A_identifier"));
boolean success = populateObjectFromPage(requestScope, obj);
if (!success)
{
  // Marker
  return;
}
session.update(obj);
To "undo" the changes in the !success block, call session.evict(obj) where the Marker comment is.

You can also evict the object earlier, then use session.merge() instead of session.update() to save the detached object.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 4:23 am 
Newbie

Joined: Thu Jun 01, 2006 5:09 am
Posts: 16
I don't know if I'm a brainstone or hibernate documentation is not so clear. However thanks my saver. I understand more things by your 2 posts than by a month of studying.
Bye
Peppe


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