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