-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: issue on sessionfactory.openSession(conn) in hibernate 4.2
PostPosted: Fri Sep 11, 2015 5:29 am 
Newbie

Joined: Thu Jan 08, 2015 5:49 am
Posts: 2
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();
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.