-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to make data not save without call update in transaction
PostPosted: Tue May 23, 2006 6:05 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 1:26 am
Posts: 20
We have a project with our servlet controller to control transactions. We want data been call session.update/delete/save to save into database and data no call these function do not save into database. How to do this?
for example:

Session s = DBM.getSession();
final String CHANGED_NOT_SAVED = "cc";
final String CHANGED_SAVED = "aa";

MUser user = (MUser)s.load(MUser.class,new Long(30085));
user.setUpdatedBy(CHANGED_SAVED); //expect this data to save into DB
DBM.saveOrUpdate(user);

user.setUpdatedBy(CHANGED_NOT_SAVED); //expect this data DO NOT to save into DB, for jsp showing only

DBM.closeSession(); //commit here

//reload , should not updated fot later value
s = DBM.getSession();

user = (MUser)s.load(MUser.class,new Long(30085));
assertFalse(CHANGED_NOT_SAVED.equals(user.getUpdatedBy()));

assertTrue(CHANGED_SAVED.equals(user.getUpdatedBy()));

DBM.closeSession();

Please help us!!

_________________
OR maping? not familar. seems easy select, hard delete/update


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 6:29 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 1:26 am
Posts: 20
We use hibernate 2.1.8, I just don't know, if call update() data will save into database, if not call update(), data will also save into database. what is the different?

_________________
OR maping? not familar. seems easy select, hard delete/update


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 8:07 am 
Beginner
Beginner

Joined: Fri Oct 22, 2004 4:47 pm
Posts: 22
Call a flush() on the session object after you run the save. This will comit the changes to the DB.


Paul


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 9:04 am 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
If you change something in an object, and your cascade setting is enabled (e.g. set to save-update), Hibernate will detect that change and persist it to db whenever you close the session (it checks for updates during session closing). You can put this line into your config file:

<property name="hibernate.connection.autocommit">false</property>

This should disable the auto-flush during session commit. However, from there on you will have to call session.flush() yourself whenever you want to commit changes (after save, update, etc.).

HTH,

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 3:22 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 1:26 am
Posts: 20
I can make sure all save using DBM.save***(), not use Session.save**().
I can flush in DBM.save**(). is this ok for above steps?
I commit in servlet controller in filter. not just after save(), but after modify model object for showing in jsp.

_________________
OR maping? not familar. seems easy select, hard delete/update


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 3:52 am 
Beginner
Beginner

Joined: Tue Mar 15, 2005 1:26 am
Posts: 20
and for the following steps:
1. save
2. delete
3. update
4. set values for hibernate model object without calling save or update.
5. commit.

I want step 1-3 is in one transaction, step 4 is ignore when commit.

_________________
OR maping? not familar. seems easy select, hard delete/update


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