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.  [ 9 posts ] 
Author Message
 Post subject: index() and Map
PostPosted: Wed Nov 26, 2003 4:58 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Hello,

I'm trying to use ths index() function of Hibernate 2.1rc6.

I have the following query :

Code:
select article, index(val)
from  Article article
join article.listFamZVVal val


where listFamZVVal is a map (whose key is of type FamZV and value of type FamZVVal).

When i execute the query, I have :

Code:
Caused by: net.sf.hibernate.QueryException: could not resolve property: index of: fr.infologic.global.zonesvariables.modele.FamZVVal [select article, index(val) from  fr.infologic.superviseur.fichiersinterface.modele.Article article  join article.listFamZVVal val]
   at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:35)
   at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:242)
   at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:281)
   at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:14)




Any explanation ?

Thanks

Philippe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 7:56 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
What are you trying to achieve exactly ?
Retrieve the article together with all the keys defined in your Map ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:50 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
brenuart wrote:
What are you trying to achieve exactly ?
Retrieve the article together with all the keys defined in your Map ?


Well, a more "realistic" query would be :

Code:
select val, index(val)
from  Article article
join article.listFamZVVal val
where article = ?


in order to have all keys and values of the map for a given Article (I have the same problem with this query).

In fact, what I want to do finally is :
select article
from Article article
join article.listFamZVVal val
where index(val) = ?
order by val.libelle

(it means, order Article with an attribut of a value of the map for a given index).

Philippe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:20 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
If that's what you wanna do, why not trying the following:

Code:
from Article article join fetch article.listFamZVVal where article=?


The fetch clause will tell hibernate to initialize your map at the same time it loads the Article.
After that, your map contains all its values and you get query it for its keys the normal way (using the collection API).

Now, if you don't want the values of the map being loaded (only the keys), then you should do:

Code:
select indices(article.listFamZVVal) from Article article where article = ?


(not sure it works though - never tried - Hibernate may not accept the indices() keyword in the select)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:22 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Sorry, have hit the submit key too fast...
You said:

Quote:
Well, a more "realistic" query would be :
Code:
select val, index(val)
from  Article article
join article.listFamZVVal val
where article = ?


This let me believe you want the keys AND the values... then my first example above should be ok.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Is this a many-to-many or a many-to-one?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:43 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Unfortunately, it seems that the index() built-in function doesn't work for Map declared with <index-many-to-many>. I had a look at examples given with Hibernate sources and can only find examples for Map with simple <index>.

Philippe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 9:25 am 
Newbie

Joined: Tue Dec 16, 2003 6:38 am
Posts: 5
Hi,

Can we have this function working for many-to-many relations?

Is there a different way to get the HBM_INDEX value from the mapping?

Thank you,
Teodor


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 22, 2005 8:42 am 
Newbie

Joined: Sat Jan 22, 2005 8:23 am
Posts: 1
tdtd wrote:
Is there a different way to get the HBM_INDEX value from the mapping?

You can refer to the map index column name directly. However, the column name has to be unique within the query.

E.g., assuming:
Code:
<class name="FooClass">
   ...
   <map name="theMap" lazy="true">
      <key column='theFoo' />
      <index-many-to-many
         column="theIndex"
         class="IndexClass" />
      <many-to-many
         column="theValue"
         class="ValueClass" />
   </map>
</class>

You would normally write something like:
Code:
select ...
    from FooClass as myFoo
    left outer join foo.theMap as myMap
where
    index(myMap) = 42 and ...

But index() won't work, so you can write:
Code:
select ...
    from FooClass as myFoo
    left outer join foo.theMap as myMap
where
    theIndex = 42 and ...

This will not work if there's a column named "theIndex" in either FooClass or ValueClass, because the joins will create a name collision.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.