I have a many-to-many relationship, where inside the parent the relation is set to this:
Code:
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name="eppl_manufacturer_has_eppl_component",
joinColumns = { @JoinColumn(name= "eppl_manufacturerID")},
inverseJoinColumns = { @ JoinColumn( name = "eppl_componentID")})
public Set<EpplComponent> getEpplComponentList() {
return epplComponentList;
}
public void setEpplComponentList( Set<EpplComponent> epplComponentList ) {
this.epplComponentList = epplComponentList;
}
Parent object is:
EpplManufacturer.classChild object(s):
EpplComponent.classNow, I need to get an EpplManufacturer with all childrens (EpplComponent), where the parameter of an EpplComponent is active.
Code:
public class EpplComponent implements java.io.Serializable {
private int epplComponentId;
private boolean isActive;
....
If I do this:
Code:
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Criteria crit = session.createCriteria(EpplManufacturer.class);
crit.add( Restrictions.eq( "epplManufacturerId", 11 ) );
crit.createAlias( "epplComponentList", "comp", CriteriaSpecification.LEFT_JOIN ).add( Restrictions.eq( "comp.isActive", true ) );
EpplManufacturer manu = ( EpplManufacturer )crit.setMaxResults( 1 ).uniqueResult();
I am getting only one child! It seems, like I'm not getting the other one. I know for sure, there are
2!
I need to display the Manufacturer and all its childrens (EpplComponent), where the flag
isActive is set to true!
It looks so trivial, but I can't get it to run... :(