Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help

 
Jasmine kaur
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
{
logger.trace("Entry:getSRsRequiringRejection");
// UC-CORE-ASS002 Reject Detection event
// This retrieves a list of SummaryRecord entities from the
// SUMMARYRECORD
// 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.


 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use below property for SQL queries:

 
Jasmine kaur
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m not sure about EJB with JPA but in hibernate we need to enabel the show queries in hibernate.cfg.xml file like :-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic