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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:01:42+00:00 2026-05-21T20:01:42+00:00

Suppose that I have the following HBM mapping: <class name=Student table=student> <set name=classes table=student_classes

  • 0

Suppose that I have the following HBM mapping:

<class name="Student" table="student">
    <set name="classes" table="student_classes" cascade="none">
        <key column="studentId" />
        <many-to-many column="classId" class="org.myCompany.myClass" />
    </set>
</class>

In my student POJO, I have the following:

private Set<myClass> classes = new HashSet<myClass>();
public Set<myClass> getClasses() { return classes; }
public void setClasses(Set<myClass> classes) { this.classes = classes; }

I want to run the following HQL query:

select count(*) from Student where classes.className = :myClassName

However, hibernate throws the following exception:

ERROR [service-j2ee-4] PARSER.reportError(33) |  Invalid path: 'classes.className'
ERROR [service-j2ee-4] PARSER.reportError(33) | <AST>:0:0: unexpected end of subtree
ERROR [service-j2ee-4] PARSER.reportError(33) |  left-hand operand of a binary operator was null
org.hibernate.hql.ast.QuerySyntaxException: Invalid path: 'classes.className' [select count(*) from Student where classes.className = :myClassName  and  1=1]

Is it possible to run a hibernate query which returns results based on properties of a Set? In the above example, we might want to query for all students who are taking ‘Algebra I’ or another course?

Edit: I enabled the appropriate debug mode to get Hibernate to output it’s actual SQL query and here is the query that it generates:

select count(*) as col_0_0_ 
from student student0_, student_classes student1_, classes student2_

where student0_.studentId=student1_.studentId and student1_.classId=student2_.classId and student2_.className LIKE 'algebra' and 1=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-21T20:01:42+00:00Added an answer on May 21, 2026 at 8:01 pm
    select count(s.id) from Student s
    inner join s.classes clazz
    where clazz.className = :myClassName
    

    Here’s how I reason about it : classes is a Set, and thus doesn’t have a className property. Once you traverse the relationship using a join, you get an alias on the myClass entity, which has a className property.

    Note: classes in Java should always begin with an upper-case letter. Rename myClass to MyClass.

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

Sidebar

Related Questions

Suppose that I have the following mapping with a formula property: <class name=Planet table=planets>
Suppose that we have the following base and derived classes: #include <string> #include <iostream>
Suppose that we have the following partial ER diagram: Notice that the attachments table
Let's suppose that I have the following class which tries to be immutable public
suppose I have the following source table (called S): name gender code Bob 0
Suppose that I have a table with the following schema: tableId field1 field2 .....
Suppose that I have a Java class with a static method, like so: class
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
Suppose that I have the following code: private void UpdateDB(QuoteDataSet dataSet, Strint tableName) {
Lets suppose that I have the following simple query var q = from p

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.