-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to post multiple saveorupdate from a single form?
PostPosted: Thu Jul 05, 2007 9:35 pm 
Newbie

Joined: Thu Jul 05, 2007 9:24 pm
Posts: 6
Hi
I am a newbie.. I have a form with multiple names and few other columns like address and phone number, in a form. For everyname in that list, the rest of the columns in that form are same. That means the address, telephone etcc are same for all the users. When I am trying to put the saveorUpdate method (for each user) in a loop and save them to a database, only the last name in the list gets saved in the database and rest of the users in the list are not saved. I am wondering how to resolve this problem. Do i have to do anything with the configuration file etc... Please throw some light on this as I have just started learning on hibernate :)

_________________
Gopu


Top
 Profile  
 
 Post subject: How to post multiple saveorupdate from a single form?
PostPosted: Thu Jul 05, 2007 10:04 pm 
Newbie

Joined: Thu Jul 05, 2007 9:24 pm
Posts: 6
Basically I would like to know whether it is possible to do multiple transactions in a single session? If so how I do that?
Regards

_________________
Gopu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 2:35 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi Gopu,

Basically I would like to know whether it is possible to do multiple transactions in a single session? If so how I do that?

Yes. It is possible to do multiple transaction in a single session. Find piece fof sample code to do that,

Session session = getSession();
for (int i=0;i<2 ;i++) {
Transaction trans = session.beginTransaction();
Employee employee = new Employee();
employee.setName("RAM"+i);
employee.setCity("CHENNAI");
employee.setDob(new Date("15-JUL-77"));
employee.setCountry("INDIA");
session.save(employee);
trans.commit();
}
session.close();

Regards
Shanmugam

Don't forget to rate if it is useful.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 2:48 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
If second transaction get failed due to some reason then first one will get commited into DB. Usually this type of design approach(More transaction with in single session) is not recommended.


Top
 Profile  
 
 Post subject: How to post multiple saveorupdate from a single form?
PostPosted: Fri Jul 06, 2007 2:54 am 
Newbie

Joined: Thu Jul 05, 2007 9:24 pm
Posts: 6
Yes,
I did try with calling saveorudate method inside a for loop, and only the last in the list gets updated in the database where as all other entries are not saved. But still dono how to solve?

Quote:

for (int i=0; i < sampleName.length; i++)
{

String tmp = sampleName[i];

sample.getDetail().setName(tmp);

this.saveOrUpdateSample(sample);

}

[code][/code]

_________________
Gopu


Top
 Profile  
 
 Post subject: How to post multiple saveorupdate from a single form?
PostPosted: Sun Jul 08, 2007 9:21 pm 
Newbie

Joined: Thu Jul 05, 2007 9:24 pm
Posts: 6
Yes, I couldn't save more than 1 form from one session. I would like to know of any other possibilities.
Thx.

_________________
Gopu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 09, 2007 1:13 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Gopu,
I want know how are you handling transaction in your code. Because if you use Hibernate default transaction (JDBC transaction) then you have to call commit() method of transaction object inside a for loop.

If you call commit() outside the the loop then only one record(final one) will get committed into DB.

Or if you use JTA transaction the n try to call flush() of session object after calling saveOrUpdate().


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