I have done upgrade from Hibernate 3.6 to Hibernate 4.2 and Java 7 to Java8. before upgrade it was working fine, now I'm facing issue with two java files Session tempSession = HibernateUtil.getSessionFactory().openSession(conn); i'm not able to pass conn object to openSession method.please find the below code. pls provide some ideas or solution wherther i need to miss jars or deprecated?? this error is i got on sts spring tool 1.The method openSession() in the type SessionFactory is not applicable for the arguments (Connection) -- AuditLogUtil.java 2. The method openSession() in the type SessionFactory is not applicable for the arguments(AuditLogInterceptor--HbernateUtil.java
AuditLogUtil.java ================== import java.sql.Connection; import java.util.Date;
import org.hibernate.Session; import org.hibernate.internal.SessionImpl;
import com.appfoundation.itrac3.domain.AuditLog; import com.appfoundation.itrac3.domain.TbMasUsers; import com.appfoundation.itrac3.dao.interfaces.IAuditLog;
import com.appfoundation.itrac3.misc.HibernateUtil; import com.appfoundation.itrac3.services.implementations.SessionServiceImpl;
public class AuditLogUtil{ public static void LogIt(String action, IAuditLog entity, Connection conn) throws Exception{ SessionServiceImpl sessionServiceImpl=new SessionServiceImpl(); TbMasUsers tbMasUsers=(TbMasUsers) sessionServiceImpl.getUserInSession(); Integer loingEmpId=Integer.parseInt(tbMasUsers.getIntEmpId().getStrEmpId()); //SessionImpl sessionImpl = (SessionImpl) session.doWork(); //Connection conn1 = sessionImpl.doWork(); Session tempSession = HibernateUtil.getSessionFactory().openSession(conn); try { @SuppressWarnings("null") AuditLog auditRecord = new AuditLog(action,entity.getLogDeatil() , new Date(),entity.getId(), entity.getClass().toString(),loingEmpId); tempSession.save(auditRecord); tempSession.flush(); } finally { tempSession.close(); } } }
HibernateUtil.java ====================
import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil { private static Configuration configuration; private static ServiceRegistry serviceRegistry; private static SessionFactory sessionFactory; private static final ThreadLocal threadSession = new ThreadLocal(); private static final ThreadLocal threadTransaction = new ThreadLocal(); private static final ThreadLocal threadInterceptor = new ThreadLocal(); static { try { System.out.println("inside hibernate util before calling annotation configuration"); // configuration = new AnnotationConfiguration(); System.out.println("inside hibernate util after calling annotation configuration before building sessionFactory"); // sessionFactory = configuration.configure().buildSessionFactory(); // hibernate4.3.1 jar update version code Configuration configuration = new Configuration(); configuration.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings( configuration.getProperties()). buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); System.out.println("inside hibernate util after calling annotation configuration after building sessionFactory"); System.out.println("static intializer of HibenrateUtil"); if(sessionFactory == null){ System.out.println("session factory is null"); }else{ System.out.println("session factory is not null"); } } catch (Exception ex) { ex.printStackTrace(); } } public static Session getSession() throws HibernateException{ //System.out.println("inside getSession method"); Session s = (Session) threadSession.get(); try { if (s == null || !s.isOpen()) { AuditLogInterceptor interceptor = new AuditLogInterceptor(); s = sessionFactory.openSession(interceptor); interceptor.setSession(s); } threadSession.set(s); //System.out.println("session :"+s); } catch (HibernateException ex) { throw new HibernateException(ex); } return s; } public static SessionFactory getSessionFactory() { return sessionFactory; } public static void shutdown() { // Close caches and connection pools getSessionFactory().close(); }
}
|