-->
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: Open Connections
PostPosted: Thu Mar 25, 2004 9:59 am 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
Hi,
I'm using the ThreadLocal pattern with Hibernate.

The architecture is jsp->Action->Delegate->EJB->Hibernate/DAO

I need to connect to two datasources, but not within the same transaction.

My first transaction begins at the ejb layer, (connects to a datasource1) and later ends at the ejb. Then the second transaction begins again at the ejb (and tries to connect to a second datasource -datasource2).

My first transaction goes through fine, but when I try to get a connection in the second transaction, it throws up with the exception stating that I'm trying to connect to multiple databases within one transaction. Which is not correct because my first transaction was completed before I started the second. I've done a session.flush() and session.disconnect() .

The same data access works fine when I replace Hibernate with DAO.

Would anyone know why this happens? Do I need to do anything more to communicate to Hibernate that this is a new transaction?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You"re doing something woring somewhere but there is not enough info

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 12:16 am 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
Hi,
I just figured that I was missing session.connection().close() .

I was doing a session.connection().commit() earlier, but that didn't seem to help.
With the connection.close(), it releases the connection assosicated with the SessionFactory and the second connection goes through without the problem mentioned earlier.

I guess it is mandatory to close the connection explicitly, if your are not using Hibernate's connection pool.

Thanks for the help.
-Ram.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 4:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You should close the session, which will close the connection unless it's a UserConnection (managed by you from the begining to the end)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 4:53 am 
Newbie

Joined: Tue Mar 09, 2004 8:58 am
Posts: 15
Ok, but in my case the connection being a user supplied one, I had to do the closing explicitly.

-Thanks Ram.


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.