-->
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 for children objects
PostPosted: Wed Nov 17, 2010 12:12 pm 
Newbie

Joined: Tue Jun 08, 2010 2:48 am
Posts: 3
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.class
Child object(s): EpplComponent.class

Now, 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... :(


Top
 Profile  
 
 Post subject: Re: Criteria for children objects
PostPosted: Thu Nov 18, 2010 8:19 am 
Newbie

Joined: Tue Jun 08, 2010 2:48 am
Posts: 3
OK, I don't know if anyone is interested but in case. This is as far as I came to present the output I want:

Code:
       EpplManufacturer epplManufacturer = (EpplManufacturer) session.load(EpplManufacturer.class, epplManufacturerID);
       List<EpplComponent> childList = session.createFilter( epplManufacturer.getEpplComponentList(), "where this.isActive=?" ).setParameter( 0, true ).list();
      
       epplManufacturer.getEpplComponentList().removeAll( epplManufacturer.getEpplComponentList() );
       epplManufacturer.getEpplComponentList().addAll( childList );


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.