[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] DB Connections stay open after Entitymanager is closed
|
Hello,
I create EntityManager with ProxyUser from EntityManagerFactory at @PostConstruct on a Service. And close the EntityManager in @PreDestroy.
@PostConstruct
public void postConstruct() {
Map<String, Object> props = new HashMap<String, Object>();
props.put("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
props.put(oracle.jdbc.OracleConnection.PROXY_USER_NAME, 'USERNAME');
entityManager = emf.createEntityManager(props);
}
@PreDestroy
public void preDestroy() {
entityManager.clear();
entityManager.close();
entityManager = null;
}
But on the Database the Sessions still exists. With a view work on the Webserver the DB (or the Pool) are not able to open new connections because of running out of resources.
How can I force to close a connection by closing the EntityManager?
Or do I have something missconfigured?
Persistence.xml (PersistenceUnite)
----------------------------------
<persistence-unit name="ArgusB_CorePU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/ARGUSDatabase</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.session-name" value="ArgusB_CorePU" />
<property name="eclipselink.cache.type.default" value="Weak" />
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.target-database" value="Oracle10g"/>
<property name="eclipselink.target-server" value="SunAS9"/>
<property name="eclipselink.session.customizer" value="ch.braunvieh.argus_core.datamgmt.logic.ArgusSessionCustomizer"/>
</properties>
</persistence-unit>
Applicationcontext (Spring configuration)
-----------------------------------------
<context:annotation-config />
<!--<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver" />-->
<context:load-time-weaver />
<tx:annotation-driven />
<tx:jta-transaction-manager />
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/ARGUSDatabase" />
<!--<jee:jndi-lookup id="emf" jndi-name="persistence/ArgusB_CorePU"/>-->
<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/ArgusB_CorePU"/>
<!--<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" />-->
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform" />
<property name="showSql" value="true" />
</bean>
Service.java
------------
public abstract class SpringEntityService<E> {
protected EntityManager entityManager;
@PersistenceUnit
protected EntityManagerFactory emf;
@PostConstruct
public void postConstruct() {
Map<String, Object> props = new HashMap<String, Object>();
props.put("eclipselink.oracle.proxy-type", oracle.jdbc.OracleConnection.PROXYTYPE_USER_NAME);
props.put(oracle.jdbc.OracleConnection.PROXY_USER_NAME, 'USERNAME');
entityManager = emf.createEntityManager(props);
}
@PreDestroy
public void preDestroy() {
entityManager.clear();
entityManager.close();
entityManager = null;
}
@Transactional
public E refreshEntity(E entity) {
//entity = entityManager.merge(entity);
entityManager.refresh(entity);
return entity;
}
}
Thanks for any help
Berner Martin