-->
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: Hibernate Session Factory
PostPosted: Thu Sep 05, 2013 6:59 am 
Newbie

Joined: Thu Sep 05, 2013 6:05 am
Posts: 1
Hi, guys :)
In our application we have HibernateSessionFactory class,that is open and close connections. Everything is okay,but when we are updating data in the database,it doesn't changes in our application.Unfortunately, we see old data from the database.Help me,please.
Here is my HibernateSessionFactory class :

public class HibernateSessionFactory {

private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static org.hibernate.SessionFactory sessionFactory;

private static Configuration configuration = new Configuration();
private static ServiceRegistry serviceRegistry;

private static final Logger log = Logger.getLogger(HibernateSessionFactory.class);

static {
try {
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
. buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Exception e) {
log.error("Error Creating SessionFactory",e);

}
}

private HibernateSessionFactory() {
}

public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;

threadLocal.set(session);
}
return session;
}

public static void rebuildSessionFactory() {

try {
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder(). applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Exception e) {
log.error("Error Creating SessionFactory",e);
}
}

public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.flush();
session.close();

}
}

public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}

public static Configuration getConfiguration() {
return configuration;
}

}


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.