It's not a secret anymore!
The moose likes JPA Certification (OCEJPA) and the fly likes Need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Need help" Watch "Need help" New topic

Need help

Jasmine kaur
Ranch Hand

Joined: Nov 25, 2003
Posts: 160
Hi All,

In our project we have used EJB3.0 and JPA and while working on this we need to see the sql queries formed by JPA
which can help us what joins are getting establish and locks so that we can improve our query, so I need to know
how to see the sql query formed by JPA at run time .
These are the queries

@NamedQuery(name = DetectionEvent.RETRIEVE_DE_LIST_FOR_REPROCESSING, query = "SELECT DISTINCT de "
+ " FROM DetectionEvent de " + "WHERE de.reprocessDE = '" + LrucConstants.DB_YES
+ "' ORDER BY de.chargePointId, de.captureDatetime ASC"),

and this is a method

public List<SummaryRecord> getSRsRequiringRejection(Timestamp pStartTime, Timestamp pEndTime)
// UC-CORE-ASS002 Reject Detection event
// This retrieves a list of SummaryRecord entities from the
// table in the EventAndVURDAO where the ‘requiresRejection’ flag is
// set.
Query query = mEntityManager.createNamedQuery(SummaryRecord.RETRIEVE_SUMMARY_RECORD_LISTS);
query.setParameter(SummaryRecord.PARAM_START_TIME, pStartTime);
query.setParameter(SummaryRecord.PARAM_END_TIME, pEndTime);
List<SummaryRecord> summaryRecord = query.getResultList();
return summaryRecord;
Need to see complete query which is getting generated at runtime so that I can see locks and joins on the table so that w ecan make improvements ..
Please tell us how to acheive this in JPA.

Thanks in advance.

jasmine kaur
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 466

You can use below property for SQL queries:

Vinod Tiwari | Twitter | Shikshanirman | Guftgu
Jasmine kaur
Ranch Hand

Joined: Nov 25, 2003
Posts: 160
Hi Vinod ,

Thanks and If Im correct I need to put this in persistence.xml file and this seeting will help me to print the query which is created at runtime by JPA.
Please correct me ifIm wrong.

Thanks alot
Singh Harmeet
Ranch Hand

Joined: Aug 05, 2011
Posts: 115

i m not sure about EJB with JPA but in hibernate we need to enabel the show queries in hibernate.cfg.xml file like :-

With Regards :-
Harmeet Singh
I agree. Here's the link:
subject: Need help
It's not a secret anymore!