-->
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.  [ 2 posts ] 
Author Message
 Post subject: Use Hibernates sql connection for queries without Hibernate?
PostPosted: Tue Apr 08, 2008 8:25 am 
Newbie

Joined: Tue Jan 15, 2008 4:11 am
Posts: 4
Location: Belgium
Is the following possible and save:

(1) I use OSIV, with a single transaction / session per request,
I implement this with a servlet filter.
(2) I implement my own ConnectionProvider, which retrieves a java.sql.Connection from a datasource.

Now my question is, can I safely execute queries on the same java.sql.Connection through plain JDBC (without Hibernate)
(in the same transaction Hibernate uses),
or will this conflict with Hibernate (or is this only possible with JDBC transaction demarcation)?
If I understood correctly, the Hibernate Session class runs in a seperate thread?

The reason why I want to do this:
We have applications which want to go to database with the same datasource using plain JDBC, using a java.sql.Connection which spans the whole request,
transaction management is done using plain JDBC demarcation.
If I use a seperate connection (not the one Hibernate uses) from the same datasource pool, we might get deadlocking problems if two threads have obtained the last two remaining connections, and then both request a second (but the pool is empty).

Or would a better solution be:
Use two datasources: one for Hibernate, one for plain JDBC? This would solve the deadlocking problem.
Problem is then that there are actually two somewhat unrelated transactions running concurrently.

To make things more complicated:
sometimes someone wants to do an intermediate commit,
so this really is difficult, because I want to have a single transaction/session.

_________________
Sincerely,

Joost Winne


Top
 Profile  
 
 Post subject: Re: Use Hibernates sql connection for queries without Hibern
PostPosted: Tue Apr 08, 2008 10:52 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It depends what you do with the connection. May be the worst that can happen is that you mess up with caches and the data you get is not what you think it is. I don't think hibernate is running in a different thread. These are delegations in a single thread. At the same time I am not sure if checking out two connections will do any good for you since some (or most?) managed data sources return the same connection for a transaction unless they configured not to do so.



Farzad-


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