I apologize for asking a very vague question.
Version: 2.1.6
Mapping Doc
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="kedar.Foo" table="foo">
<id name="id" column="id" type="int">
<generator class="uuid.hex"/>
</id>
<map name="ages">
<key column="id"/>
<index-many-to-many column="person_id" class="kedar.Person"/>
<element column="age" type="string"/>
</map>
</class>
<class name="kedar.Person" table="person">
<id name="id" column="id" type="int">
<generator class="uuid.hex"/>
</id>
<property name="name" column="name" type="string"/>
</class>
</hibernate-mapping>
Code:
select f from Foo f inner join f.ages.indices persons where persons.id in( 1, 2)
Problem: This query does not work.
When I use the following query
select f from Foo f inner join f.ages persons where persons.id
hibernate translates it as
select foo0_.id as x0_0_ from foo foo0_, ages ages1_ where foo0_.id=ages1_.id and ((ages1_.age in(1, 2) ))
What i want is to select Foo where Persons have a specific id.
Working Solution:
select f from Foo f where 1 in indices(f.ages)
Hibernate translates this as
select foo0_.id as x0_0_ from foo foo0_ where (1 in(select ages1_.person_id from ages ages1_ where foo0_.id=ages1_.id))
which is fine, but does not perform well when i have multiple values to compare with i.e. it will result in multiple queries.
Question:
How do I get this query to work?
Thanks
|