I'm using Jasper Reviews for report generation.

I'm using temporary tables to create reviews that I want exactly the same connection utilized by JPA while creating temporary table how do you attain the same.

Within JasperReports you should use either native JDBC queries or EJBQL queries.

While using the latter, your code need to look such as this (from JRJpaQueryExecuter api):

 Map parameters = new HashMap();
 EntityManager em = emf.createEntityManager();
 parameters.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, em);
 JasperRunManager.runReportToPdfFile(fileName, parameters);

If you actually need the underlaying jdbc connection the best way to do it varies with respect to the JPA implementation you're using.

EclipseLink (JPA 2.):

entityManager.getTransaction().begin();
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class);
...
entityManager.getTransaction().commit();

(You will not have to begin and commit transactions for confirming)

Most likely you're just three steps away.

It can be done using following way

  1. use JTA datasource for persistance.xml like as below

    <persistence-unit name="sample">
            <jta-data-source>java:comp/env/jdbc/DBConnectionDS</jta-data-source>
            ....
    </persistence-unit>
    
  2. For report generation, retrieve the connection from datasource as proven below

    InitialContext initialContext = new InitialContext();
    DataSource dataSource = (DataSource)initialContext.lookup("java:comp/env/jdbc/DBConnectionDS");
    Connection connection = dataSource.getConnection();
    
  3. Make use of the link with generate report something similar to below:

    JasperPrint print = JasperFillManager.fillReport(report, parameters, connection);
    

This ought to be all In my opinion. The concept is, using common JNDI connection for, JPA &lifier JasperReport, after which rely on them where relevant.

I did not use JasperReports, but labored with BIRT Report and solved it by doing this with no problem.