-->
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.  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Fri Sep 02, 2005 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Transaction demarcation code has no place in a DAO. I've explained this already in this thread and don't want to do it again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
However what about applications which use hibernate to talk to several database servers? HibernateUtil is a static class.


It's really really trivial to extend this class with a few lines to support several SessionFactories. All you need is a getSession(String persistenceUnit) method. Maybe you want to try it yourself this time?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 12:58 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 8:41 pm
Posts: 47
Christian,

Quote:
Transaction demarcation code has no place in a DAO. I've explained this already in this thread and don't want to do it again.


I wasn't making a point or asking about transaction demarcation at all. But speaking about
transaction demarcation in DAO

http://cvs.sourceforge.net/viewcvs.py/hibernate/CaveatEmptor/HiA-SE/src/java/org/hibernate/ce/auction/dao/hibernate/GenericHibernateDAO.java?rev=1.5&view=auto

shouldn't HibernateUtil.beginTransaction() calls go away from DAOs in CaveatEmptor (GenericHibernateDAO.java)?

Don't get me wrong the reason I'm posting here is a wish
to have CaveatEmptor code usable for more people and to share
experiences with it.

Regards,
--MG


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is a reason that beginTransaction() is there. Because it just joins any ongoing transaction. If none exists, it starts one. This is called "lazy" behavior, something that is very well documented in everything that was linked to in this thread. It's also very optional. I'm not sure I like to continue this discussion at this level.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And yes, your suggestion to make getSession() a method to override is a good one and I'll think about it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 4:16 am 
Beginner
Beginner

Joined: Sat Sep 04, 2004 7:07 am
Posts: 20
Location: Helsinki, Finland
Returning to the beginning of this thread. It wasn't totally trivial to debug or trace the error which resulted in net.sf.hibernate.HibernateException: Session is closed. Therefore it might be reasonable to do this:

christian wrote:
... I'd probably check if the transaction is still uncommitted in the close() method and throw an exception.

_________________
Risto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:26 am 
Beginner
Beginner

Joined: Sat Sep 04, 2004 7:07 am
Posts: 20
Location: Helsinki, Finland
It's easy to make the (somewhat abstract) mistake of closing the session and simultaneously not committing the transaction. But I'm reluctant to add 'own' functionality to the HiberateUtil which would throw exception in this situation -- partly to be able to use the next official version of the HibernateUtil 'straight out of the box'.

_________________
Risto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 23 posts ]  Go to page Previous  1, 2

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.