0

can I extrapolate the query in SQL format from the javax.persistence.Query Object. I generate the Obj Query from a query in JPQL format.

This is my source code

Statless.java

Query documentiQry = getEntityManager().createNamedQuery(Entity.QRY);
documentiQry.setParameter(Entity.PARAM_ONE, a);
documentiQry.setParameter(Entity.PARAM_TWO, b);

Entity.java

@Entity(name = "Entity")
@Table(schema = "Z", name = "ENTITY")
@NamedQuery(name = Entity.QRY, query = Entity.QRY_VALUE)
public class Entity{

    public final static String PARAM_ONE = "paramOne";
    public final static String PARAM_TWO = "paramTwo";

    public final static String QRY       = "qry";
    public final static String QRY_VALUE =  "SELECT e FROM Entity e WHERE e.columnOne = :"+PARAM_ONE +" AND e.columnTwo = :"+PARAM_TWO;
ponticello
  • 21
  • 3
  • Do you mean you are looking for a way to automatically translate any JPQL query to native SQL? – Jannis Alexakis Apr 30 '14 at 10:11
  • I'm not sure of a standard way, but most JPA providers usually allow you to log or retrieve the native SQL. For example, with EclipseLink: http://stackoverflow.com/a/12104141/1671856 – DannyMo May 01 '14 at 17:02

0 Answers0