Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:09:04+00:00 2026-06-06T22:09:04+00:00

I need to execute a subquery in a select clause with Apache Openjpa 2.

  • 0

I need to execute a subquery in a select clause with Apache Openjpa 2.
Does JPA support subqueries in SELECT clause?

My Query is something like this:

SELECT t.date, t.value, 
  (SELECT COUNT(DISTINCT t2.value2) FROM table t2 WHERE t2.date = t.date)
FROM table t
WHERE ...

When I execute my query, I get a class cast exception:

Exception in thread "main" <openjpa-2.1.1-SNAPSHOT-r422266:1141200 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: 
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
    at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
    at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:315)
    at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:331)
Caused by: java.lang.ClassCastException: org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect incompatible with org.apache.openjpa.jdbc.sql.SelectImpl
    at org.apache.openjpa.jdbc.sql.SelectImpl.setParent(SelectImpl.java:579)
    at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.newSelect(SelectConstructor.java:147)
    at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:87)
    at org.apache.openjpa.jdbc.kernel.exps.SubQ.appendTo(SubQ.java:209)
    at org.apache.openjpa.jdbc.kernel.exps.SubQ.appendTo(SubQ.java:203)
    at org.apache.openjpa.jdbc.kernel.exps.SubQ.newSQLBuffer(SubQ.java:167)
    at org.apache.openjpa.jdbc.kernel.exps.SubQ.selectColumns(SubQ.java:153)
    at org.apache.openjpa.jdbc.kernel.exps.SubQ.select(SubQ.java:148)
    at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.select(SelectConstructor.java:372)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.populateSelect(JDBCStoreQuery.java:295)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.access$100(JDBCStoreQuery.java:86)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery$1.select(JDBCStoreQuery.java:267)
    at org.apache.openjpa.jdbc.sql.LogicalUnion.select(LogicalUnion.java:297)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.populateUnion(JDBCStoreQuery.java:265)
    at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:211)
    at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:782)
    at org.apache.openjpa.datacache.QueryCacheStoreQuery$QueryCacheExecutor.executeQuery(QueryCacheStoreQuery.java:346)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
    at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
    ... 6 more

Is this possible or do I have to use NativeQuery / Single Queries?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:09:08+00:00Added an answer on June 6, 2026 at 10:09 pm

    No, it is not supported to use subqueries in SELECT clause. In JPA 2.0 specification this is told with following words:

    Subqueries may be used in the WHERE or HAVING clauses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to execute mysql query like this? select (select A from B
I need to execute a SQL Query between two databases. Example: SELECT * from
I need execute 2 select in SQLAlchemy. For example: select1 = Session.query(col1, col2, col3,
In SQL Server 2008. I need execute a query like that: DECLARE @x AS
I need to execute this simple mysql query in Zend; UPDATE `table` SET `field`='field'+1
I need execute an SQL query in ORACLE it takes a certain amount of
I need execute an update statement over an sql server table. This table is
I need to execute the following MySQL-query in Oracle: INSERT INTO users VALUES(1,10) ON
I need to execute from Java a batch script, which does following 1) Once
I need to execute a select and then update some of the rows in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.