jpa-spec
  1. jpa-spec
  2. JPA_SPEC-25

Add support to retrieve JPQL query from Query object

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Labels:
      None

      Description

      Currently the interfaces javax.persistence.criteria.AbstractQuery and javax.persistence.Query have no support for retrieving the underlying JPQL Query for additional transformation which would be, especially for named queries, very useful! Just think of the fact, that you currently have to copy and paste a named query if you like to have exactly the same query with an additional predicate in the where clause. The predicate in the where clause is just an example, there are probably tons of use cases where this feature would be helpful and minimize redundant code!

      I would suggest to add the following methods:

      Query.java
      public interface Query{
        // currently available methods...
      
        public String getQuery();
      }
      
      AbstractQuery.java
      public interface AbstractQuery{
        // currently available methods...
      
        public String getQuery();
      }
      

        Activity

        Hide
        Antonio Goncalves added a comment -

        As I wrote on my blog (http://agoncal.wordpress.com/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/), having the JPQL String representation of a CriteriaQuery is very useful for debugging purpose. And going further, having the SQL String would also be useful. I would go for :

        public interface Query {
        
          public String getJPQLQuery();
          public String getSQLQuery();
        
        }
        
        Show
        Antonio Goncalves added a comment - As I wrote on my blog ( http://agoncal.wordpress.com/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/ ), having the JPQL String representation of a CriteriaQuery is very useful for debugging purpose. And going further, having the SQL String would also be useful. I would go for : public interface Query { public String getJPQLQuery(); public String getSQLQuery(); }
        Hide
        ldemichiel added a comment -

        Being able to map back and forth between CriteriaQueries and JPQL queries would be useful to have. This is something that should be considered in a future release. See also http://java.net/jira/browse/JPA_SPEC-29

        Show
        ldemichiel added a comment - Being able to map back and forth between CriteriaQueries and JPQL queries would be useful to have. This is something that should be considered in a future release. See also http://java.net/jira/browse/JPA_SPEC-29

          People

          • Assignee:
            ldemichiel
            Reporter:
            c.beikov
          • Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated: