Atitit. Getting connection Hibernate4

Source: Internet
Author: User

Atitit. Get Connection Hibernate4

1. Sessionfactoryutils method (Recommended ) 1

2. ConnectionProvider Law (1 )

3. GA self-Implementation ( not recommended ) read HB configuration file 1

4. Or use work (but the working black Conn is a closure, not good for use) 1

1. Sessionfactoryutilsmethod (recommended )

Multiple conn generated by this method are actually one , so it's not good to use

Hibernate3.3.2 version getsession (). Connection () has been deprecated, alternative method Sessionfactoryutils.getdatasource (Getsessionfactory ()). Getconnection ()

Author :: Old Wow's paw attilax ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

2.ConnectionProviderLaw ( )

Jas. 10 , This method generates multiple conn that are actually one , so it's not good to use

ConnectionProvider CP = ((sessionfactoryimplementor) ssn.getsessionfactory ()). Getconnectionprovider ();

3. GA Self-Realizationmethod ( not recommended ) to read the HB configuration file

Read the HB configuration file and generate con from the JDBC API

C = New hb4jdbcx(). getconnection ();

Wechat4propty Project :

// C = cp.getconnection ();

4. Or use work (but the Conn is a closure, it's not good to use)

BD . Bind (Connection. class ). toinstance (

(Connection) New Closure2() {

@Override

Public object execute( object arg0) {

Baseimpl basedao = new baseimpl();

sessionfactory sessionfactory = hibernatesessionfactory. getsessionfactory ();

Connection c;

Try  {

C  =  sessionfactoryutils . Getdatasource (sessionfactory ). getconnection ();

} catch (SQLException e) {

//  TODO auto-generated Catch block

e . Printstacktrace ();

Throw new runtimeexception(e);

}

return c;

}

}. Execute (null));

Hibernate Session gets connection-liuxianbing119 's Column - Blog channel -CSDN. Net.htm

Atitit. Getting connection Hibernate4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.