-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL SELECT for "object whose bag contains <x>&
PostPosted: Tue Oct 17, 2006 4:11 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
I've looked at the help and searched the forums, and I'm sure I'm just missing something so I hate asking but I can't find the answer.

Let's say I've got a mapping like this:

Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
               assembly="Eg" namespace="Eg">
   <class name="A" table="A">
      <id name="Id">
         <generator class="assigned"/>
      </id>
      <bag name="Bees" cascade="all">
         <key column="AId" />
         <one-to-many class="B" />
      </bag>
   </class>
</hibernate-mapping>


It is a one-way (not bidirectional) mapping from A->B, and I have an instance of B. I want to retrieve the object of type A that contains my instance of type B. Is there an HQL or ICriteria way of doing this?

Thanks!


Last edited by jstelly on Thu Oct 19, 2006 1:57 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 1:57 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
Is there really no way to do this, or is my question just too stupid to deserve an answer(like I said, I might have missed something very basic)? It's simple to do in SQL and would probably work on any platform I care about, but I'd really like to avoid using any SQL if I could.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 2:59 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
What about "from A a join fetch a.Bees b where b.Name = 'x'" (or b.Id or any other unique way to identify your B instance).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 1:39 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
GeAr wrote:
What about "from A a join fetch a.Bees b where b.Name = 'x'" (or b.Id or any other unique way to identify your B instance).


Sure enough, that works. For some reason it wasn't clear that you could do a join like that on a collection. Thanks for the help.


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