generic count report for JPQL query

Discussion in 'Java' started by Giovanni Azua, May 31, 2009.

  1. hello,

    Suppose I'm given a valid JPQL query and I would like to find out how many
    rows it would return if executed but without actually executing it.

    Example input JPQL: select p from Person p where p.name like "Giov%"

    and I would like to generate something like (this one does not work):

    select count(e) from (<the input query here>) e
    select count(e) from (select p from Person p where p.name = "Giovanni") e

    I have tried several JPQL possibilities without success. The context of this
    problem is while implementing the Value List Handler Pattern, the lazy
    strategy would not execute the actual query immediately but needs to know
    what the total number of records is so the iterator state can be consistent.

    The other possibility I was considering was to accept not only the query as
    input but also the corresponding count reporting query too. However, this is
    somewhat redundant and error-prone because the client could in theory hand
    in a wrong reporting query that would not match the original query.

    I think this kind of query is ANSI SQL therefore supported by all Database
    vendors, hence using native queries would be cool ... but it feels wrong
    stepping aside from JPQL

    TIA,
    regards,
    Giovanni
    Giovanni Azua, May 31, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Murat Tasan
    Replies:
    1
    Views:
    8,026
    Chaitanya
    Feb 3, 2009
  2. Replies:
    2
    Views:
    423
  3. marek
    Replies:
    1
    Views:
    439
    Tris Orendorff
    Mar 12, 2008
  4. minlearn
    Replies:
    2
    Views:
    445
    red floyd
    Mar 13, 2009
  5. efelnavarro09
    Replies:
    2
    Views:
    915
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page