• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Subqueries in JPA is not working with OpenJPA

 
                      
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does JPA support subqueries in the select part of the main query.

For example :

SELECT record1.txnId, record1.accessTime, (SELECT record2.accessTime FROM Metering record2 WHERE record2.txnId=record1.txnId AND record2.action='END') FROM Metering record1 WHERE record1.action='START'

The above query is properly working with Hibernate implementation. But when i use OpenJPA implementation instead of Hibernate implementation it is giving the following error:

org.springframework.dao.InvalidDataAccessApiUsageException: Encountered "(" at character 44, but expected: ["ABS", "AVG", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "LENGTH", "LOCATE", "LOWER", "MAX", "MIN", "MOD", "NEW", "OBJECT", "SIZE", "SQRT", "SUBSTRING", "SUM", "TRIM", "UPPER", <IDENTIFIER>].; nested exception is <openjpa-1.2.1-r752877:753278 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Encountered "(" at character 44, but expected: ["ABS", "AVG", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "LENGTH", "LOCATE", "LOWER", "MAX", "MIN", "MOD", "NEW", "OBJECT", "SIZE", "SQRT", "SUBSTRING", "SUM", "TRIM", "UPPER", <IDENTIFIER>].
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not sure.....but you might want to give an alias to the term that you have selected like

SELECT record1.txnId, record1.accessTime, (SELECT record2.accessTime FROM Metering record2 WHERE record2.txnId=record1.txnId AND record2.action='END') AS accessTime FROM Metering record1 WHERE record1.action='START'
 
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic