I have two models :
class A extends Model {
public bool active = true;
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(
name = "a_with_b",
joinColumns = {@JoinColumn (name="a_id")},
inverseJoinColumns = {@JoinColumn (name="b_id")}
)
public List<B> bs;
}
class B extends Model {
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(
name = "a_with_b",
joinColumns = {@JoinColumn (name="b_id")},
inverseJoinColumns = {@JoinColumn (name="a_id")}
)
public List<A> as;
}
and I’m trying to find all the A elements where B is defined, like this :
B b = B.findById(1L);
List<A> as = A.find("active = ? AND b IN ?", false, b); // This doesn't work :/
How should I do ?
Thanks for your help
the only way I know how to do this is defining a relation table and using hql.
your tables would be something like this
for details check the link below
http://java-aap.blogspot.com/2006/04/hibernate-annotations-composite.html
and your hql will look something like this
But after writing all that I think you could just use a JOIN whith your current structure.