1

I have a JSF, EclipseLink app. I use JasperReports, to export a report I need to create a connection.

JasperPrint jasperPrint = JasperFillManager.fillReport(File, Hash Map, Connection)

I cant access my current connection (The datasource I define in the persistence xml). I have tried different ways, but the only thing that has worked is creating a new connection. I dont feel really good about hard coding the connection parameters in my code. Is there a way I can read the parameters of the datasource, so I can create the connection with the same parameters?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Daniel Rojas
  • 407
  • 2
  • 5
  • 16

1 Answers1

1

I'm not sure what you mean you cannot access the connection from persistence.xml as if you are using a datasource, it is defined elsewhere and the persistence.xml is used to define how the provider should get it from the container. So if it is a datasource, the persistence unit will not have any information on the connection itself, but you should be able to look it up from the container.

You can get the connection from EclipseLink as described here: http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

You can also use this code to get the login object from the session, which will contain the connection information if you are not using a datasource.

Chris
  • 20,138
  • 2
  • 29
  • 43
  • Thanks a lot for the help. When I try the first method, the 2.0. It returns a closed connection. And wont let me use the lines:entityManager.getTransaction().begin(); Because of an exception : Caused by: java.lang.IllegalStateException: Exception Description: Cannot use an EntityTransaction while using JTA. – Daniel Rojas Jan 18 '12 at 03:38
  • And by the way what do you men a login object? Thanks in advance. – Daniel Rojas Jan 18 '12 at 03:55