-->
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 existing JDBC connection
PostPosted: Thu Feb 28, 2008 6:03 am 
Newbie

Joined: Tue Dec 04, 2007 10:11 am
Posts: 2
Location: Germany
Hi,

I want to introduce Hibernate to an existing project that uses plain JDBC connections for DB access so far. I may not replace all existing JDBC code, but I could use Hibernate functionality for all new modules.

The existing application uses real database accounts where a new JDBC connection is created for each user during login. It is a mandatory requirement for me to keep this architecture. Another requirement is to reuse the existing JDBC connection.

Is this possible with Hibernate? How can this be done? How do I have to configure Hibernate to achieve such a solution?

Best regards,
Ralf.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 10:58 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Configure your SessionFactory with out database properties like URL, username and pasword.

Then whenever you call openSession method on SessionFactory, supply your current Connection.

Code:
public Session openSession(Connection connection)


So this way, session always uses your connection. But you will lose some benefits that hibernate offers when you use your own connection. One of them is Second Level Cache will be disabled.

Other options to use existing project JDBC Connection is configure the ConnectionProvider with SessionFactory. And then make this ConnectionProvider to use your database properties to make connections.


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.