当前位置:  开发笔记 > 编程语言 > 正文

没有活动事务,get无效 - hibernate 5

如何解决《没有活动事务,get无效-hibernate5》经验,为你挑选了0个好方法。

即使我手动启动了交易,我仍然会收到此错误.

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.getTransaction();
if(!transaction.isActive())
{
    transaction = session.beginTransaction();
}

accessToken = session.get(OAuthAccessToken.class, token);

hibernate.cfg.xml

true

    
    5
    20
    300
    50
    3000

    
    org.hibernate.cache.NoCacheProvider
    false
    false
    3

    
    thread

    30

HibernateUtils

public class HibernateUtil
{
private static final SessionFactory sessionFactory;

static
{
    try
    {
        // Create the SessionFactory from hibernate.cfg.xml
        Configuration config = new Configuration().configure();
        config.setProperty("hibernate.show_sql", String.valueOf(ConfigManager.getInstance().getBoolean(Consts.CONFIG_DB_SHOW_SQL, false)));
        config.setProperty("hibernate.format_sql", String.valueOf(ConfigManager.getInstance().getBoolean(Consts.CONFIG_DB_FORMAT_SQL, false)));

        config.setProperty("hibernate.dialect", ConfigManager.getInstance().getString(Consts.CONFIG_DB_DIALECT, "org.hibernate.dialect.MySQLDialect"));
        config.setProperty("hibernate.connection.driver_class", ConfigManager.getInstance().getString(Consts.CONFIG_DB_DRIVER_CLASS, "com.mysql.jdbc.Driver"));
        config.setProperty("hibernate.connection.url", ConfigManager.getInstance().getString(Consts.CONFIG_DB_URL, "jdbc:mysql://localhost/photometo"));
        config.setProperty("hibernate.connection.useUnicode", "true");
        config.setProperty("hibernate.connection.characterEncoding", "UTF-8");
        config.setProperty("hibernate.connection.username", ConfigManager.getInstance().getString(Consts.CONFIG_DB_USERNAME, "root"));
        config.setProperty("hibernate.connection.password", ConfigManager.getInstance().getString(Consts.CONFIG_DB_PASSWORD, ""));
        config.setProperty("hibernate.hbm2ddl.auto", ConfigManager.getInstance().getString(Consts.CONFIG_DB_HBMDDL_AUTO, "update"));
        sessionFactory = config.buildSessionFactory();
    }
    catch (Throwable ex)
    {
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory()
{
    return sessionFactory;
}

}

我注意到这会在一段时间后开始发生.如果我重新启动tomcat或重新部署应用程序,问题就会消失

推荐阅读
mobiledu2402851377
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有