-->
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: Replacing Session.connection() in Hibernate 4
PostPosted: Fri Aug 19, 2011 10:35 am 
Newbie

Joined: Thu May 08, 2008 3:11 pm
Posts: 6
Location: Mountain View, CA
I've read through the hibernate 4 migration guide, and noted the removal of Session.connection() for obtaining JDBC Connection instance. According to the migration guide, I should instead be using Session.doWork() or Session.connectionWithOptions(), but neither of these approaches gives me direct access to a JDBC Connection instance.

I understand the design principle behind removing direction access to the managed JDBC Connections. I believe that the 'right' approach for my application (we use the JasperReports reporting engine, which requires a JBDC Connection object when invoking the API) would be to access the c3p0 connection pool directly. Our application would get a Connection instance from c3p0 and then release that connection back to the pool upon completion of the work.

Is that the 'best practice' in the Hibernate 4.x world?


Top
 Profile  
 
 Post subject: Re: Replacing Session.connection() in Hibernate 4
PostPosted: Sat Aug 20, 2011 5:18 pm 
Newbie

Joined: Thu May 08, 2008 3:11 pm
Posts: 6
Location: Mountain View, CA
Just for the record, here is the solution that I have implemented in my Hibernate 4 testing branch:

Code:
public Connection getConnection() {
        try {
            String jdbcURL = "jdbc:postgresql://hostname:port/databaseName";
            DataSource ds_unpooled = DataSources.unpooledDataSource(jdbcURL, "username", "password");
            Connection c  = ds_unpooled.getConnection();
            return c;
        } catch (SQLException e) {
            LOGGER.error("Unable to get SQL Connection: ", e);
            return null;
        }

    }


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.