-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria reverse reference
PostPosted: Mon Apr 06, 2009 8:12 am 
Newbie

Joined: Thu Jan 29, 2009 10:18 am
Posts: 4
Hi,
I have two classes
class Product {
Integer id;
}
class Characteristic {
Integer id;
@ManyToOne
Product product;
String type;
}

I want to select products which have characteristic.type="foo"
SELECT product.* INNER JOIN characteristic on ( characteristic.product_id = product.id ) WHERE characteristic.type="foo";

Can i do this via Criteria API?
The method ัriteria.createCriteria("...") won't work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 10:00 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You can only use criteria on mapped associations. In your case you need an association to Characteristic in your product:
Code:
class Product {
@Id
Integer id;

@OneToMany(mappedBy="product")
private Set<Characteristic> characteristics;
}


Now you can use criteria.createCriteria("characteristics",...).

_________________
-----------------
Need advanced help? http://www.viada.eu


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