我正在使用spring transactional和hibernate。
当我调用正在使用事务的流时,似乎在单个流上使用了2个连接!
似乎hibernate没有使用Spring事务检索的相同连接。 所以如果我看到我的池中使用了多少个连接,我会看到如下
我错过了什么吗?
我知道在两个层(服务和dao)都有交易功能并不常见,但现在这不是我的问题
请注意,如果在Dao我询问会话我确实看到它已连接并且它有一个事务(isConnected = true,getTransaction()有一个
我正在使用spring和hibernate(v.4.1.7) 我正在使用C3P0连接提供商 和底层的MySql数据库
服务
@Transactional
public StudentEntity getStudentById(String id) {
StudentEntity entity = dao.getStudentById(id);
return entity;
}
Dao
@Transactional
public StudentEntity getStudentById(String id) {
//I have a sessionFactory provider - singleton
Criteria criteria = this.getCurrentSession().createCriteria(StudentEntity.class);
criteria.add(Restrictions.eq(StudentEntity.MEMBER_ID, id));
this.getCurrentSession().isConnected()//true !
Object entity = criteria.uniqueResult();
return (StudentEntity)entity;
}
服务筹码
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(long) BasicResourcePool.java:1414
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(long) BasicResourcePool.java:606
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(long) BasicResourcePool.java:526
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse() C3P0PooledConnectionPool.java:755
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection() C3P0PooledConnectionPool.java:682
com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection() AbstractPoolBackedDataSource.java:140
org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(Object, TransactionDefinition) DataSourceTransactionManager.java:204
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(TransactionDefinition) AbstractPlatformTransactionManager.java:373
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(PlatformTransactionManager, TransactionAttribute, String) TransactionAspectSupport.java:463
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(Method, Class, TransactionAspectSupport$InvocationCallback) TransactionAspectSupport.java:276
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(MethodInvocation) TransactionInterceptor.java:96
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() ReflectiveMethodInvocation.java:179
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(MethodInvocation) ExposeInvocationInterceptor.java:92
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed() ReflectiveMethodInvocation.java:179
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(Object, Method, Object[]) JdkDynamicAopProxy.java:207
com.sun.proxy.$Proxy80.getStudent(String)
Dao Stack
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(long) BasicResourcePool.java:526
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse() C3P0PooledConnectionPool.java:755
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection() C3P0PooledConnectionPool.java:682
com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection() AbstractPoolBackedDataSource.java:140
com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection() AbstractPoolBackedDataSource.java:140
org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection() InjectedDataSourceConnectionProvider.java:70
com.XXXX.XXXX.XXXX.MyMultiTenantConnectionProvider.getAnyConnection() MyMultiTenantConnectionProvider.java:43
com.XXXX.XXXX.XXXX.MyMultiTenantConnectionProvider.getConnection(String) MyMultiTenantConnectionProvider.java:53
org.hibernate.internal.AbstractSessionImpl$ContextualJdbcConnectionAccess.obtainConnection() AbstractSessionImpl.java:344
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection() LogicalConnectionImpl.java:214
org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection() LogicalConnectionImpl.java:157
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection() StatementPreparerImpl.java:56
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare() StatementPreparerImpl.java:159
org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement() StatementPreparerImpl.java:183
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(String, boolean, ScrollMode) StatementPreparerImpl.java:157
org.hibernate.loader.Loader.prepareQueryStatement(String, QueryParameters, LimitHandler, boolean, SessionImplementor) Loader.java:1881
org.hibernate.loader.Loader.executeQueryStatement(String, QueryParameters, boolean, List, SessionImplementor) Loader.java:1858
org.hibernate.loader.Loader.executeQueryStatement(QueryParameters, boolean, List, SessionImplementor) Loader.java:1838
org.hibernate.loader.Loader.doQuery(SessionImplementor, QueryParameters, boolean, ResultTransformer) Loader.java:906
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean, ResultTransformer) Loader.java:348
org.hibernate.loader.Loader.doList(SessionImplementor, QueryParameters, ResultTransformer) Loader.java:2550
org.hibernate.loader.Loader.doList(SessionImplementor, QueryParameters) Loader.java:2536
org.hibernate.loader.Loader.listIgnoreQueryCache(SessionImplementor, QueryParameters) Loader.java:2366
org.hibernate.loader.Loader.list(SessionImplementor, QueryParameters, Set, Type[]) Loader.java:2361
org.hibernate.loader.criteria.CriteriaLoader.list(SessionImplementor) CriteriaLoader.java:124
org.hibernate.internal.SessionImpl.list(Criteria) SessionImpl.java:1587
org.hibernate.internal.CriteriaImpl.list() CriteriaImpl.java:374
org.hibernate.internal.CriteriaImpl.uniqueResult() CriteriaImpl.java:396