HQL query for the Set property

Suppose 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 POJO student, 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, sleep mode 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]

Can I run a sleep request that returns results based on the Set properties? In the above example, can we request all students who take Algebra I or another course?

Edit: I turned on the appropriate debugging mode to force Hibernate to output this actual SQL query, and here is the query 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;
+3
source share
2 answers
select count(s.id) from Student s
inner join s.classes clazz
where clazz.className = :myClassName

: classes - Set , , className. , myClass, className.

: Java . myClass myClass.

+3

hibernatequery, Set?

!

, org.myCompany.myClass ha a className? , - select count(*) from Student s inner join Classes c where c.className = :myClassName

0

All Articles