Atitit. Get connection hibernate4, atitithibernate4

Source: Internet
Author: User

Atitit. Get connection hibernate4, atitithibernate4

Atitit. Get connection hibernate4

 

1. SessionFactoryUtils method (recommended) 1

2. ConnectionProvider method () 1

3. Ga self-implementation method (not recommended) read hb configuration file 1

4. Or use work (but the conn of work blackheads is a closure, which is not easy to use) 1

 

1. SessionFactoryUtils method (recommended)

Multiple Conns generated by this method are actually one, so it is not easy to use.

In Hibernate3.3.2, getSession (). connection () has been discarded. The alternative method is SessionFactoryUtils. getDataSource (getSessionFactory (). getConnection ()

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

2. ConnectionProvider method ()

Ya 10, multiple Conns generated by this method are actually one, so it is not easy to use

 

ConnectionProvider cp = (SessionFactoryImplementor) ssn. getSessionFactory (). getConnectionProvider ();

 

3. Read the hb configuration file using the self-implementation method (not recommended)

Read the hb configuration file and use the jdbc api to generate con

C = new Hb4JdbcX (). getConnection ();

 

Wechat4propty project ..

// C = cp. getConnection ();

 

 

4. Or use work (but the conn of work blackheads is a closure, which is not easy 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;

}

Cmd.exe cute (null ));

 

Obtain the connection-liuxianbing119 column from Hibernate Session-blog channel-CSDN.NET.htm

Related Article

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.