Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] DB Connections stay open after Entitymanager isclosed

Your application uses a jta data source (jdbc/ARGUSDatabase).
In this case Eclipselink always releases connections when the jta transaction is completed; or (with no jta transaction active) immediately after the query is executed.

The proxy session is never opened, because Eclipselink can't get hands on OracleConnection - an attempt to write through the em created with PROXYTYPE would have resulted in exception stating that: "OracleJDBC_10_1_0_2ProxyConnectionCustomizer requires datasource producing OracleConnections."

To make it work you need to implement public java.sql.Connection unwrapConnection(java.sql.Connection connection) method on SunAS9ServerPlatform.

----- Original Message ----- From: <martin.berner@xxxxxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, January 21, 2010 9:47 AM
Subject: [eclipselink-users] DB Connections stay open after Entitymanager isclosed


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

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top