-->
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: last object not saved -- newbie problem
PostPosted: Mon Apr 04, 2005 4:07 am 
Newbie

Joined: Mon Mar 21, 2005 9:41 am
Posts: 12
Hello to everybody,

I have a problem saving an object into the db while processing a loop.
The last object of that loop is never saved. It is no problem of the loop, because I checked with debbugging output whether session.save() and session.flush() is called or not. It is called every time.
After every save()-call I call session.flush() to ensure persistence in DB. Nevertheless the last object remains unsaved...
I also put a session.connection.commit() instead of/in addition to flush(), but it has no effect.

Are there any problems with longlasting/unfinished sessions?

Does anybody know an answer to that problem?


Hibernate version:2.1.2

I am using FireBird 1.5 DB


Thank you,
matze


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 8:16 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Any chance you could post your code? That would probably help. Cheers ~


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 10:38 am 
Newbie

Joined: Mon Mar 21, 2005 9:41 am
Posts: 12
the code that performs the session.save() is mainly a function
like this:

Task resultTask = new Task();
//setting properties of resultTask...

try{
this.session = ThreadSession.get();
this.session.save(resultTask);
try{
this.session.connection().commit();
}catch(SQLException ex){
logger.error(ex);
}
this.session.flush();
this.logger.info("saved task:" + resultTask.getName());
}catch(HibernateException ex){
this.logger.error("error while saving task: " +
resultTask.getName(), ex);
return null;
}

there's a logging statement for every task that needs to be saved including the last that is *not* saved. So I presume that it has to be something with my session.flush behaviour...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you need to understand how the session works, please read the reference guide again, Hibernate in action too.

2 tips:
- take care of transaction
- flush is not commit

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 3:09 am 
Newbie

Joined: Mon Mar 21, 2005 9:41 am
Posts: 12
Thanks to everybody that answered.

It was the wrong use of transactions. Works fine now....
matze


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.