-->
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: IN statement on a OneToMany relationship
PostPosted: Fri Jan 16, 2009 9:03 am 
Newbie

Joined: Mon Mar 28, 2005 7:40 am
Posts: 5
Hibernate version: 3

Can I Apply a IN filter on a OneToMany property? Like this:

Code:
@Entity
class Car{
  ....
  @OneToMany(mappedBy="car")
  private List<Component> components;
  ...
}

@Entity
class Component{
  ...
  @MayToOne
  @JoinColumn(name="car_id")
  public Car car;
}

I want to do this:
Code:
session.createCriteria(Car.class).add(Restrictions.in("components",getFilteredComponents()));


getFilteredComponentes returns a Collection<Component>

I get the error "Missing IN or OUT parameter at index:: 1"
The generated query is
Code:
select this_.car_id as id1_1_0_, this_.model as model2_1_0_
from cars this_ where this_.car_id in (?)


Any Ideas??
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 4:39 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
I don't know for sure but as far as I know this is not possible with criteria query api. But a little tip for you: use the inverse way. In each of your component (getFilteredComponents()) there is already the car attached. So you only have to collect them.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.