openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From is_maximum <mnr...@gmail.com>
Subject Re: EntityManager dosn't release connection in XA transactions
Date Wed, 23 Dec 2009 07:51:56 GMT

That snippet code are actually two individual method we created to test if
this is the EntityManager that hold the connection. both are executed in a
XA transaction.

In second addAccount() in which we use EntityManager after the transaction
being commited the connection pool shows that no connection is released. As
far as I know we cannot call the close() method of EntityManager manually so
we rely on the container to manage the connections, in result after a couple
of hours we encounter an exception complains that no connection can be
allocated !!! but in first addAccount() method we never face this error.

My question is why this happens? Do we have to increase the number of
connections in the pool? if yes Won't we again face the above problem after
a couple of hours or more? or we need to release the connection manually? 

BTW, what is strange is that when we use
TransactionAttributeType.REQUIRES_NEW the connection will be released
automatically but in this case a new transaction for Java services are
created and will be differed from the one created in .NET client

thanks Pinaki
 


Pinaki Poddar wrote:
> 
> The code does not show when/where the connections are released ... neither
> the method that uses native SQL nor the method that uses EntityManager
> (for which the app server should manage connection reuse/pooling). 
> Are you sure it is not the native SQL method that is leaking the
> connections?
> 
> 
> 
> is_maximum wrote:
>> 
>> FYI, we have monitored our connection pool, when using DataSource the
>> NumConnDestroyed is increased after each statement execution but using
>> EntityManager the NumConnDestroyed is always 0 
>> 
>> here is the snippet code and more details:
>> 
>> 
>> Datasource Classname: oracle.jdbc.xa.client.OracleXADataSource
>> Resource Type: javax.sql.XADataSource
>> 
>> Oracle Version: 10.2.0.1.0
>> Oracle JDBC Driver Version: 10.2.0.1.0
>> Glassfish: 9.1_02 (build b04-fcs)
>> OpenJPA: 1.2.1
>> 
>> 
>> @Resource(name="jdbc/myDS", type=javax.sql.DataSource.class)
>> private DataSource dataSource;
>> 
>> @WebMethod(operationName="addAccount")
>>       @TransactionAttribute(TransactionAttributeType.REQUIRED)
>>       public String addAccount(){
>>             String accountCode;
>>             String sql = "INSERT INTO ACCOUNT …";
>>             Connection connection = null;
>>             Statement statement = null;
>>             try{
>>                   
>>                   connection = dataSource.getConnection();
>>                   
>>                   statement = connection.createStatement();
>>                   statement.executeUpdate(sql);
>>                   
>>                   
>>             }catch(SQLException exception){
>>                   //…
>>             }
>>             
>> return accountCode;
>>       }
>> 
>>       
>> @PersistenceContext(unitName="pu-cm")
>>       protected EntityManager entityManager;
>> 
>> @WebMethod(operationName="addAccount")
>>       @TransactionAttribute(TransactionAttributeType.REQUIRED)
>>       public String addAccount(){
>>             String accountCode;
>>             Account account =  new Account();
>> 
>>             account.setAmount(10.0);
>>             //…
>> 
>>             entityManager.persist(account);
>>             entityManager.flush();
>>             
>>             return accountCode;
>>       }
>> 
>> 
> 
> 
http://n2.nabble.com/file/n4207600/sample-j2ee-project2.rar
sample-j2ee-project2.rar 

-----
--
Regards
Mohammad
http://pixelshot.wordpress.com Pixelshot 
-- 
View this message in context: http://n2.nabble.com/EntityManager-dosn-t-release-connection-in-XA-transactions-tp4205041p4207600.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message