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 1008957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:51:09+00:00 2026-05-16T08:51:09+00:00

What is the correct way to write this JPA query? I am just guessing

  • 0

What is the correct way to write this JPA query? I am just guessing as I cant work it out or find it in my JPA book.

Query query=em.createQuery("select m from Meeting m where count(m.attendees) = 0");
return query.getResultList();

I am currently trying this with Hibernate and I get a mysql error!

ERROR org.hibernate.util.JDBCExceptionReporter - You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ')=0' at line 1
  • 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-05-16T08:51:10+00:00Added an answer on May 16, 2026 at 8:51 am

    To strictly answer the title of the question, use SIZE:

    Query query=em.createQuery("select m from Meeting m where size(m.attendees) = 0");
    return query.getResultList();
    

    From the JPA specification:

    4.6.16.2 Arithmetic Functions

    functions_returning_numerics::=
    ABS(simple_arithmetic_expression) |
    SQRT(simple_arithmetic_expression) |
    MOD(simple_arithmetic_expression, simple_arithmetic_expression) |
    SIZE(collection_valued_path_expression)
    

    The ABS function takes a numeric
    argument and returns a number
    (integer, float, or double) of the
    same type as the argument to the
    function.

    The SQRT function takes a numeric
    argument and returns a double.

    The MOD function takes two integer
    arguments and returns an integer.

    The SIZE function returns an integer
    value, the number of elements of the
    collection. If the collection is
    empty, the SIZE function evaluates to
    zero.

    Numeric arguments to these functions
    may correspond to the numeric Java
    object types as well as the primitive
    numeric types.

    In the particular case of 0, you could also use IS EMPTY

    4.6.11 Empty Collection Comparison Expressions

    The syntax for the use of the
    comparison operator IS EMPTY in an
    empty_collection_comparison_expression
    is as follows:

    collection_valued_path_expression IS [NOT] EMPTY
    

    This expression tests whether or not
    the collection designated by the
    collection-valued path expression is
    empty (i.e, has no elements).

    Example:

    SELECT o
    FROM Order o
    WHERE o.lineItems IS EMPTY
    

    If the value of the collection-valued
    path expression in an empty collection
    comparison expression is unknown, the
    value of the empty comparison
    expression is unknown.

    I would test both to see which one is the most efficient (check the query plan).

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

Sidebar

Related Questions

No related questions found

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.