**我的hibernate版本已经过时了,我迁移到了3.6,它可以完美地运行,并且试图从3.6迁移到4.3.11。但是我在HibernateUtils中遇到了麻烦,有几个“ java.lang .Error:未解决的编译问题” **这是我的HibernateUtil中的一部分
Session s = (Session) threadSession.get();
try {
if (null == s || !s.isOpen() || !s.isConnected()) {
if (null != getInterceptor()) {
WLog.DAOLogger.debug("Using interceptor: " + getInterceptor().getClass());
s = getSessionFactory().openSession(getInterceptor());
} // end if
else {
s = getSessionFactory().openSession();
if (testConnections) {
Connection c = s.connection();
这是我的堆栈跟踪
java.lang.Error:未解决的编译问题: SessionFactory类型的openSession()方法不适用于自变量(拦截器) 对于会话类型,未定义方法connection()
我正在使用hibernate 4.3.11。在HIbernateUtil中没有弃用最终版本和连接
这是HibernateUtils的一小段使用连接的代码
public static void executeDDL( String ddl ) {
Session session = HibernateUtils.getSessionFactory().openSession();
Connection conn = session.connection();
try {
Statement stmt = conn.createStatement();
stmt.executeUpdate( ddl );
stmt.close();
} catch( SQLException e ) {
throw new HibernateException( "Can't execute DDL'" + ddl + "'.", e );
} finally {
Settings settings = HibernateUtils.getConfiguration().buildSettings();
if( settings.getConnectionReleaseMode() == ConnectionReleaseMode.AFTER_STATEMENT ) {
try {
conn.close();
} catch( SQLException e ) {
WLog.ProjectLogger.error( "Can't close SQL connection", e );
}
}
session.close();
}
}