|
code is simply like that : (not use @Transactional) =========java code============= em.getTransaction().begin(); TypedQuery<TaskEntity> query1 = em.createQuery(queryHQL, TaskEntity.class).setMaxResults(500); em.getTransaction().commit(); ==========java code======
==========c3p0 configuration======== <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="$ {jdbc.driverClassName}
" /> <property name="jdbcUrl" value="$ {jdbc.url}
" /> <property name="user" value="$ {jdbc.username}
" /> <property name="password" value="$ {jdbc.password}
" /> <property name="minPoolSize" value="2" /> <property name="maxPoolSize" value="5" /> <property name="maxStatements" value="0" /> <property name="idleConnectionTestPeriod" value="10" /> <property name="maxIdleTime" value="20" /> <property name="maxConnectionAge" value="7200" /> </bean> ==========c3p0 configuration===========
after I committed, I check c3p0 log and find that database connection don't release automatically,and exhaust all my production database connection,then system hung up. .
but all work well in hibernate 3.5.1; after i upgrade to Hibernate 4.3.4 ,this not work. I find a way to fix it,but ugly.I wish hibernate will fix this bug in next version.
try { em.getTransaction().begin(); TypedQuery<TaskEntity> query1 = em.createQuery(queryHQL, TaskEntity.class).setMaxResults(500); em.getTransaction().commit(); logger.debug("em.getTransaction().isActive()=" + em.getTransaction().isActive()); logger.debug("em.isOpen()===" + em.isOpen()); list = query1.getResultList(); logger.debug("list====size==" + list.size()); }
finally { if (em != null && em.isOpen()) { try { em.close(); }
catch(Exception e){
} } }
|