-->
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.  [ 9 posts ] 
Author Message
 Post subject: session.getConnection() deprecated?
PostPosted: Tue Oct 16, 2007 3:30 am 
Newbie

Joined: Mon Oct 15, 2007 8:49 pm
Posts: 7
Hibernate version: 3.2.5ga
Spring version: 2.0.7

Session session = sessionFactory.getCurrentSession();
session.getConnection(); // Deprecated???

I am trying to user Hibernate with Spring 2.x, but the above is deprecated, so how can I obtain the current connection to run some custom SQL?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 5:51 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
This is the code for getting the connection/session in Hibernate 3.0

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.getCurrentSession();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 9:46 am 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
When it says it's deprecated, that doesn't mean it won't work, necessarily, just that it's not recommended anymore. Technically, it might go away in a future release, but that seems unlikely to me.

When you say "custom SQL", note that you can still use a raw SQL query in the regular Hibernate interface. There are other things you might still need a raw Connection for, however. You might want to make sure what you're trying to do with "custom SQL" isn't already possible to do with Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 10:04 pm 
Newbie

Joined: Mon Oct 15, 2007 8:49 pm
Posts: 7
I need a connection to do some custom processing and I'd rather avoid deprecated methods. I ended up using Spring class to get the connection.

SessionFactoryUtils.getDataSource(aSF).getConnection()


I think they do use the deprecated method to get connection too though :)

Why was the call deprecated?

dkarr wrote:
When it says it's deprecated, that doesn't mean it won't work, necessarily, just that it's not recommended anymore. Technically, it might go away in a future release, but that seems unlikely to me.

When you say "custom SQL", note that you can still use a raw SQL query in the regular Hibernate interface. There are other things you might still need a raw Connection for, however. You might want to make sure what you're trying to do with "custom SQL" isn't already possible to do with Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 11:56 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
They deprecated the method in preparation for a new "SQL Work" API.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 28, 2007 11:34 pm 
Newbie

Joined: Mon Oct 15, 2007 8:49 pm
Posts: 7
VampBoy wrote:
They deprecated the method in preparation for a new "SQL Work" API.


I hope that there will still be someway to get a connection from a hibernate session though...


Top
 Profile  
 
 Post subject: Re: session.getConnection() deprecated?
PostPosted: Mon Oct 29, 2007 12:36 am 
Newbie

Joined: Fri Jun 29, 2007 9:03 am
Posts: 12
Hi,
If you are using getHibernateTemplate().
you can get session by :
Code:
getHibernateTemplate().getSessionFactory().getCurrentSession();

I hope this might help .

coder wrote:
Hibernate version: 3.2.5ga
Spring version: 2.0.7

Session session = sessionFactory.getCurrentSession();
session.getConnection(); // Deprecated???

I am trying to user Hibernate with Spring 2.x, but the above is deprecated, so how can I obtain the current connection to run some custom SQL?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 9:52 am 
Newbie

Joined: Wed Jul 23, 2008 9:27 am
Posts: 7
Hello,

I read the previous answers but they were off-topic as the pb was how to get the connection() method and not how to get a session.

So for some reason I have to create a prepared statement.
So up to now I had :

org.hibernate.Session session = getSession();
session.connection().prepareStatement(...);

But the connection() method is now deprecated.
How should I change it ?

I'm using Hibernate 3.3.0.SP1.

Thanks a lot,
Marc.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2008 1:35 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
There is a discussion about this in JIRA.
http://opensource.atlassian.com/project ... e/HHH-2603


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