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