-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: indices in Join queries
PostPosted: Fri Sep 03, 2004 7:30 pm 
Newbie

Joined: Thu Sep 02, 2004 5:31 pm
Posts: 4
I am trying to join the key part of a Map collection in a query, but the sql generated always seems to create a join condition using the value column and not the key.

Is there any way to force the join condition to work of the key rather than the value


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 04, 2004 3:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about reading the red card? we might help you then

;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Sorry for not being clear the first time
PostPosted: Mon Sep 06, 2004 12:39 pm 
Newbie

Joined: Thu Sep 02, 2004 5:31 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.