Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with EclipseLink JPA 1.0 and Glassfish 2.1(Problem with EclipseLink JPA 1.0 and Glassfish 2.1)
Problem with EclipseLink JPA 1.0 and Glassfish 2.1 [message #533382] Thu, 13 May 2010 15:48 Go to next message
Ruben Viegas is currently offline Ruben ViegasFriend
Messages: 4
Registered: May 2010
Junior Member
Hi,

I have been using EclipseLink JPA 1.0 and Glassfish 2.1 for a while now and until recently I had (gladly) no problems. I mainly used EclipseLink for database select/insert/update/delete operations and it worked fine.
Recently, I had to provide some statistical reports in various formats and I decided to use JasperReports which needs a connection to be passed to the Engine in order to build the report (the connection is needed for the sql query that extracts the data to fill the report) and export it to the desired format.
I thought that, since I have the Connection available in the EntityManager I could use that connection and pass it to JasperReports. This much is true, however after a couple of times calling that method, glassfish achieved its maximum used connections!
Glassfish is managing the connections and the EntityManager and so, I believed that I was not required to explicitly close the connection. The fact is that, as soon as I put that statement into the code, glassfish stops achieving the maximum number of used connections.
I am certain that this cannot be the solution to my problem because, for example, I will have problems if I try to call more than one report in JasperReports or to persist some entities into the database.
My question is therefore: how can I get hold of the EntityManager's database connection to pass it to JasperReports, build the report with it and letting Glassfish close the connection and the EntityManager without doing it explicitly and without consuming every connection in the connection pool?

Many thanks in advance!

Cheers
Re: Problem with EclipseLink JPA 1.0 and Glassfish 2.1 [message #533969 is a reply to message #533382] Mon, 17 May 2010 15:11 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

How do you get the JDBC connection from EclipseLink?

If you are using a Glassfish DataSource or JTA, why not just get the connection from the Glassfish DataSource instead of through EclipseLink?

Sounds like it may be Glassfish connection pool issue. You may wish to try the Glassfish forum. You could also try using EclipseLink's connection pooling.


James : Wiki : Book : Blog : Twitter
Re: Problem with EclipseLink JPA 1.0 and Glassfish 2.1 [message #534156 is a reply to message #533969] Tue, 18 May 2010 09:01 Go to previous messageGo to next message
Ruben Viegas is currently offline Ruben ViegasFriend
Messages: 4
Registered: May 2010
Junior Member
James,

I get the connection through the following code:

Connection jdbcConnection = ((JNDIConnector) ((DatabaseLogin) ((UnitOfWorkImpl) ((JpaEntityManager) em.getDelegate()).getActiveSession().getActiveUnitOfWork()).getProject().getDatasourceLogin()).getConnector()).getDataSource().getConnection();


where
em
is the reference to my EntityManager.

Is there any other way to do this?

I have already posted a thread in java.net Glassfish forum almost a month ago but I haven't received any answer yet.

Thanks
Re: Problem with EclipseLink JPA 1.0 and Glassfish 2.1 [message #534872 is a reply to message #533382] Thu, 20 May 2010 14:27 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This will give you a new connection directly from your Glassfish DataSource. You could also lookup the DataSource in JNDI or inject it. You are responsible for closing this connection, and must call close() on it when done with it.

In EclipseLink 2.0 you can use the em.unwrap(java.sql.Connection.class) API to get the JDBC connection used by the EntityManager.

In EclipseLink 1.0 you can also use, unitOfWork.getAccessor().getConnection(), and should call beginEarlyTransaction() first.


James : Wiki : Book : Blog : Twitter
Previous Topic:Native query mapping requires JPA annotations
Next Topic:Performance Issue
Goto Forum:
  


Current Time: Thu Apr 25 13:26:54 GMT 2024

Powered by FUDForum. Page generated in 0.03440 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top