小编Lil*_*yan的帖子

Hibernate Session Factory

在我们的Web应用程序中,我们有一个HibernateSessionFactory类,即打开和关闭连接.一切都很好,但是当我们更新数据库中的数据时,它在我们的应用程序中不会改变.不幸的是,我们从数据库中看到旧数据.我该如何解决?

public class HibernateSessionFactory {

    private static final ThreadLocal threadLocal = new ThreadLocal();
    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 == …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate hibernate-session java-ee

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

hibernate ×1

hibernate-session ×1

java ×1

java-ee ×1

mysql ×1