-->
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: Criteria queries and value collections
PostPosted: Wed Sep 14, 2005 11:01 am 
Newbie

Joined: Wed Sep 14, 2005 10:39 am
Posts: 4
Say I have:

Code:
<hibernate-mapping>
  <class name="Foo" table="foo">
    <id name="id" type="long">
      <generator class="native"/>
    </id>

    <map name="attribs" table="foo_attribs" cascade="all-delete-orphan">
      <key column="fooId"/>
      <map-key type="java.lang.String" column="name"/>
      <element type="java.lang.String" column="value"/>
    </map>
</hibernate-mapping>


How can I construct a Criteria query to retrieve Foo's that have an attribute with the attribute "name" of "xxxxx"....

Criterias on most other associations is simple e.g. http://www.hibernate.org/hib_docs/api/n ... teria.html. However I want something like:

Code:
   Criteria c = s.createCriteria(Foo.class)
       .createCriteria("attribs")
           .add(Restrictions.contains("somekey", "somevalue"));

    //  Or just match on key
   Criteria c = s.createCriteria(Foo.class)
       .createCriteria("attribs")
           .add(Restrictions.containsKey("somekey"));


I don't see it....
Code:
Restrictions.isEmpty()
hints at Criteria support for collections, but I can't find what I'm looking for.

Thanks,
Andy

P.S. I know how to do it with HQL, or straight SQL, I'm mainly interested in Criteria queries.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 9:43 am 
Newbie

Joined: Thu Jun 02, 2005 11:20 am
Posts: 9
maybe i'm oversimplifying

Code:
   Criteria c = s.createCriteria(Foo.class)
       .createCriteria("attribs")
           .add(Restrictions.eq("name", "somevalue"));


or for multi values:

Code:
   

String[] names = new String[] { "foo","bar" };

Criteria c = s.createCriteria(Foo.class)
       .createCriteria("attribs")
           .add(Restrictions.in("name", names));


HTH,

shanon


Top
 Profile  
 
 Post subject: Nope...
PostPosted: Thu Sep 15, 2005 9:54 am 
Newbie

Joined: Wed Sep 14, 2005 10:39 am
Posts: 4
That works for non-value based collection but in that example you'll get an exception like "collection was not an association"
http://forum.hibernate.org/viewtopic.php?t=946236

I've seen various posts with different timestamps scattered acrossed the last two years from Gavin and other Hibernate maintainers that say it isn't possible to use Criteria queries on value collections, but I was hoping otherwise.


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.