即使我手动启动了交易,我仍然会收到此错误.
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或重新部署应用程序,问题就会消失