-->
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.  [ 9 posts ] 
Author Message
 Post subject: Do I have to commit() on every response?
PostPosted: Wed Apr 20, 2005 3:31 am 
Newbie

Joined: Thu Mar 24, 2005 11:29 pm
Posts: 14
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

The question is the subj - should I be committing on every response? I've been following the caveat emptor example, and their Filter does "commit()", even though they never even use transactions....

I guess what my real question is - do I need transactions at all? If I don't use transactions, and just use session.updateOrSave(), will my objects be persisted? (that's not the case I've seen so far).

My problem with transactions is that what if I don't want the db connections to be made during the request itself... What if I'd rather use the cache for that moment, and do the rest later?

How can I do that? Transactions seem to force it, and not using transactions doesn't seem to persist it.

Thanks for any material in advance you guys, really appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 10:47 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
If you want to persist (save, update, delete) you MUST use transaction.
For plain reading (select) this is not necessary.
The connection won't be opened until absolutely necessary - if your data resides in cache --> no connection :-).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 11:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
please search the forum,
you always need a transaction.

When you execute a simple select in JDBC, you have an underlying transaction started...

This is better if you always have this in mind.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 2:26 pm 
Newbie

Joined: Thu Mar 24, 2005 11:29 pm
Posts: 14
No I understand that, but I noticed that whenever I do transaction.commit(), the server starts connecting to the database right away, and the user has to sit there and wait for it to happen, before they get a response page.

That's no big deal if I have a small commit, but what if I'm committing 10,000 statements or something? I want them to be sent to database later, and display the page to the user NOW.

How can that be accomplished?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
see http://forum.hibernate.org/viewtopic.php?t=941328

try to explain better what you are doing, seems to me that 10,000 is a batch process, so look at
http://blog.hibernate.org/cgi-bin/blosx ... batch.html

every user should know about flush and flushMode...

hope this helps

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 3:01 pm 
Newbie

Joined: Thu Mar 24, 2005 11:29 pm
Posts: 14
Thanks for the doc. I guess I kind of came at a wrong angle about the batch processing.

Let's forget about that for a second.

Say, I simply want to add an.. "Item" to a database. If I do tx.commit(), this will cause the DB connection to be established right away, while the user sits and waits for the operation to finish.

Is it possible to add that item in such way, that it's cached, instead of being saved to the database right away, so the user gets quick response, and then it's persistsed later?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 4:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Asynchronous operation usually needs some kind of queue or messaging system. You might want to search on Google for this, it's not in the scope of Hibernate (it could be on top, of course).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 5:03 pm 
Newbie

Joined: Thu Mar 24, 2005 11:29 pm
Posts: 14
Consider it for a future feature?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 5:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No! Thats what JMS products do.


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