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 afterEntitymanager isclosed

I see, you use OracleDataSource in GlassFish, I did not know that this is possible, especially when the data source is JTA-managed. In that case I was wrong about proxy, you proxy setup is correct and you don't need to implement unwrapConnection.

If the entity manager is not injected then you should call em.joinTransaction().

Whether proxy session is opened or not, the connection should be released in exactly the same way - when the JTA transaction is completed).

Could you please verify if the problem still occurs without proxy settings?
Please post the non-proxy log with FINEST log level in any case;
if the problem is unique to proxy setting then please post FINEST log for the proxy case, too.

----- Original Message ----- From: <martin.berner@xxxxxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Friday, January 22, 2010 1:16 AM
Subject: AW: [eclipselink-users] DB Connections stay open afterEntitymanager isclosed


If I understand your answer right, you are telling me that if I write true my em, I would get an Exception. But that is not the case. Reading and writing is working as expected. And User is proxyed correctly, as I can see by changing some fields on the Tables to USER by Oracle-Triggers. But the Connections stay open after em.close().

Domain.xml (on glassfish v3 prelud)
-----------------------------------
<jdbc-connection-pool datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource" description="Argus Pool Auf Testdb" name="ARGUSconnectionPool"> <property name="URL" value="jdbc:oracle:thin:@uranus.braunvieh.ch:1521:AR01" />
     <property name="Password" value="PWD" />
     <property name="User" value="UID" />
   </jdbc-connection-pool>
<jdbc-resource pool-name="ARGUSconnectionPool" description="test für Brunanet" jndi-name="jdbc/argus" />

Are you suggesting me to do the proxyting in the overdiden function "unwrapConnection"?

-----Ursprüngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-
bounces@xxxxxxxxxxx] Im Auftrag von Andrei Ilitchev
Gesendet: Donnerstag, 21. Januar 2010 17:17
An: EclipseLink User Discussions
Betreff: 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.GlassFishL
oadTimeWeaver"
/>-->
  <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.LocalContainerEntityManagerFactoryBe
an"
/>-->
  <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

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

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



Back to the top