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: Parent-Child relationship - revisited.
PostPosted: Mon Dec 13, 2004 11:07 pm 
Newbie

Joined: Fri Nov 19, 2004 6:35 am
Posts: 19
Say, I have a parent-child type of table relationship, say, Cat and Kitten.
How will I define the XML mapping or the class definition in such a way
that when I load the Cat info from the database, it will load only Kittens with, like, red noses?

Like this,
Code:
Cat c = (Cat)query.createNamedQuery( "from Cat where name = 'lovella'"  );

List kittens = c.getKittens();

Cat, "lovella", might have twenty kittens... I am only interested to get kittens with red noses... something like that.

The usual, parent-child relationship will surely load all the kittens belonged to a certain cat right?.
how will i change my xml definition to meet my needs?
(i want to get rid of other kittens that's why im planning to permanently get red-nosed kittens only).

cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 5:34 am 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
I guess you should use Cirterial instead of createNamedQuery(),the code seems like as below:

List cats=session.createCriteria(Cat.class).add(Expresssion.eq("name","lovella")).list();
Cat cat=cats.get(0);
Collection col=session.filter(cat.kitten(),"where this.nose=?","red",Hibernate.String);

Maybe you intently use named query other than criteria,then i have to get out from here becuase i have no experiment about named query in hibernate,sorry for my poor technique,it's believed someone will clear your confuse soon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 5:38 am 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
中文测试


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 7:02 am 
Newbie

Joined: Fri Nov 19, 2004 6:35 am
Posts: 19
Hi!.
Dont mind the named query. I am only interested on how I obtain red-nosed kittens. And seems like the 3rd line of your code make sense. I will try that one and I think that will work!.

Shei-shei!!.


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.