-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using the same connection pool as Hibernate, from JDBC
PostPosted: Tue Feb 03, 2004 4:09 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Hello,

Due to some minor limitations of Hibernate (can't use function in the select part of the query), I had to resort to using JDBC to execute one particular query.
To do that I still use Hibernate's Session to get a hold of java.sql.Connection (session.getConnection() method) first.
This is kind of ugly, as it creates a dependency of JDBC implementation on Hibernate's Session class. That should not be the case.

Question:
Is there a way of talking to and using the same Connection pool that Hibernate uses, instead of going through Session object?

I could eliminate Session dependency by just getting my own Connection, but then I wouldn't be using a Connection pool.
I could also just create my own Connection pool, but then I would have 2 Connection pools, which would also be ugly.

So, I am wondering if there is a way to get a reference to the same Connection pool that Hibernate is using, without depending on any Hibernate classes?

Can I get a reference to the Connection pool by a logical name, perhaps?

Thanks,
Otis


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 5:13 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
are you using a JNDI datasource? or DBCP connection pool?

If you are using JNDI you ocould try and get the javac.jdbcDatasource object...

Quote:
Due to some minor limitations of Hibernate (can't use function in the select part of the query)


Not sure thats completely true... take a look at the formula attribute... You can map a DB query or call a db function and map the single result to a property.[/url]

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 5:16 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
That's something that the Spring Framework addresses: The mechanism works the other way round there, injecting an existing DataSource into the Hibernate SessionFactory. JDBC access code can easily access this DataSource directly; Hibernate access code will work on the same DataSource through the SessionFactory. Spring-managed transactions can easily be exposed for both Hibernate and JDBC access code; JDBC access code is not aware of participating in Hibernate transactions here. See the article at http://www.hibernate.org/110.html for an introduction.

A further option that comes to my mind is to configure Hibernate for a JNDI DataSource, and access the same JNDI DataSource via plain JDBC.

Juergen
(Spring Framework developer)


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