0

**My hibernate version was outdated it was 3.1 and I migrated to 3.6 which works perfect and I was trying to migrate to 4.3.11 from 3.6.However i am having trouble in my HibernateUtils, with couple of "java.lang.Error: Unresolved compilation problems"**Here is a piece from my 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();

Here is my stacktrace

java.lang.Error: Unresolved compilation problems: The method openSession() in the type SessionFactory is not applicable for the arguments (Interceptor) The method connection() is undefined for the type Session

I am using hibernate 4.3.11.Final and connection is not deprecated in my HIbernateUtil

Here is a small piece of code from HibernateUtils which using connection

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();
    }
}
Lilac
  • 580
  • 1
  • 7
  • 25
  • Looks like I have to work on HibernateUtils but no idea what to do.Any help will be grateful. – Lilac Aug 08 '19 at 16:09
  • 1
    Possible duplicate of [session.connection() deprecated on Hibernate?](https://stackoverflow.com/questions/3526556/session-connection-deprecated-on-hibernate) – MWiesner Aug 08 '19 at 16:33
  • This migration guide will help - https://developer.jboss.org/wiki/HibernateCoreMigrationGuide40 – Sundararaj Govindasamy Aug 08 '19 at 16:35
  • https://stackoverflow.com/questions/11428410/hibernate-4-0-0final-where-is-the-sessionfactory-opensessioninterceptor-interce – Sundararaj Govindasamy Aug 08 '19 at 16:35
  • @MWiesner Thank you for suggesting, but that is not my case. I am using hibernate 4.3.11 and connection is not deprecated.Can I get some help with "java.lang.Error: Unresolved compilation problem: The method connection() is undefined for the type Session". – Lilac Aug 08 '19 at 17:14
  • @SundararajGovindasamy Link you provided helped me to solve exceptions with openSession(), However I still have compilation problem with the method "connection" in hibernateUtil.THank You.Appreciate your help..! – Lilac Aug 08 '19 at 17:17
  • *http://myjourneyonjava.blogspot.com/2014/12/different-ways-to-get-connection-object.html this link helped to solve the problem with connection which describes about different ways to use connection.* – Lilac Aug 08 '19 at 18:13

0 Answers0