-->
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.  [ 5 posts ] 
Author Message
 Post subject: Criterias for associated Objects
PostPosted: Sun Feb 25, 2007 3:16 pm 
Beginner
Beginner

Joined: Fri Nov 03, 2006 6:15 am
Posts: 21
hello,


How can i query an associated object with the ".add" method after a ".createCriteria" ?
I see in the sql output that the object is initialised but i still dont know how to access an attribute from the associated object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 12:00 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi chuanito,

For example

Criteria criteria = session.createCriteria(XYZ.class);
criteria.add(Restrictions.eq("xyz", abc));
Criteria criteria2 = criteria.createCriteria("pqr");
criteria2.add(Restrictions.eq("pqrProperty.index", "443"));



Class XYZ
{
List pqr
}

Class PQR{
RST pqrProperty;
}

Class RST{
String index,
}

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 10:51 am 
Newbie

Joined: Sat Feb 24, 2007 10:16 pm
Posts: 4
I have a related problem. In the example dharmendra gave below, assume class XYZ stored a single object of class PQR instead of a list. Then assume you have two sublcasses of PQR: ABC and DEF. My question is how to use criteria to find all XYZ objects whose PQR member variable is of type ABC.

That is, given the following relationships,

Code:
Class XYZ
{
PQR pqr;
}

Class PQR{ }

Class ABC extends PQR { }

Class DEF extents PQR { }


how do I construct a criteria query to return all XYZ objects where pqr is of type ABC?

A simple real-world example is an item and bid construct. Assuming items have categories like Electronics, Books, Music, that are all subclasses of a master Item class, and assuming that each bid stores a reference to an item, how could you find all bids for Electronics items?

Thanks,
Jacob
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 11:44 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
hi vitasthefetus,

if you have used sub class mapping by discriminator ,Try to map that column with read only property insert false update false. Then apply the criteria on that property. This might help not sure.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 4:40 am 
Newbie

Joined: Sat Feb 24, 2007 10:16 pm
Posts: 4
Thanks for the suggestion. I am using subclass mapping by discriminator, and I tried insert=false but it didn't help. Please let me know if you have any other suggestions. This seems like it would be a common problem -- maybe the solution is to frame the query in a different context? Any help will be greatly appreciated.


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