使用hibernate 偶尔会出现这种问题,疑似是不同的线程使用的同一个session,仅是怀疑,没有找到问题,而且不好复现,
通过SessionFactory获取的session
Session session = entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();
/**
* 设置Hibernate的配置属性
* @return
*/
private Properties hibernateProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.current_session_context_class", "org.springframework.orm.hibernate5.SpringSessionContext");
properties.setProperty("current_session_context_class", "org.hibernate.context.internal.ThreadLocalSessionContext");
properties.setProperty("hibernate.hbm2ddl.auto", environment.getProperty("spring.jpa.hibernate.ddl-auto"));
properties.setProperty("hibernate.show-sql", environment.getProperty("spring.jpa.properties.hibernate.show-sql"));
properties.setProperty("connection.autoReconnect","true");
properties.setProperty("connection.autoReconnectForPools","true");
properties.setProperty("connection.is-connection-validation-required","true");
//properties.setProperty("hibernate.cache.use_second_level_cache", ache.use_query_cache"));
//properties.setProperty("","");
return properties;
}
报错信息:
org.springframework.orm.hibernate5.HibernateSystemException: Could not extract result set metadata; nested exception is org.hibernate.HibernateException: Could not extract result set metadata
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:300)
at org.springframework.orm.hibernate5.HibernateExceptionTranslator.convertHibernateAccessException(HibernateExceptionTranslator.java:102)
at org.springframework.orm.hibernate5.HibernateExceptionTranslator.translateExceptionIfPossible(HibernateExceptionTranslator.java:77)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
Caused by: org.hibernate.HibernateException: Could not extract result set metadata
at org.hibernate.loader.custom.JdbcResultMetadata.<init>(JdbcResultMetadata.java:35)
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:476)
at org.hibernate.loader.Loader.processResultSet(Loader.java:2214)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2170)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1931)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893)
at org.hibernate.loader.Loader.doQuery(Loader.java:938)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2692)
at org.hibernate.loader.Loader.doList(Loader.java:2675)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
at org.hibernate.loader.Loader.list(Loader.java:2502)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335)
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2162)
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1016)
at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:152)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
at org.bizf.common.dao.impl.QueryServiceImpl.list(QueryServiceImpl.java:188)
at