-->
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.  [ 3 posts ] 
Author Message
 Post subject: Eager collection made reciprocal select.
PostPosted: Mon Jun 11, 2012 12:39 pm 
Newbie

Joined: Wed Jan 12, 2011 1:15 pm
Posts: 11
I have mapped photo album and photos. In this moment in database exists two album with two photos each one.

When the collection in album.class is LAZY, the DAO return two albums (correct) but when I transform the collection in EAGER, the DAO return four albums.

I understand that it is a real behavior but I need that the collection is EAGER and the DAO return two albums.

album.class
Code:
   @OneToMany(mappedBy="album",cascade=CascadeType.ALL,orphanRemoval=true)
   private Collection<Foto> fotos=new ArrayList<Foto>();


         /**
    * return total photos
    * @return numfotografias
    */
public Integer getContarFotografias(){
      
   return this.fotos.size();
}
   
   /**
    * Return random index photo
    * @return indexFotografia
    */
public Integer getFotografiaAleatoria(){
      
Random rand=new Random();
ArrayList<Foto> listaFotos=(ArrayList<Foto>)this.fotos;
   
// (MAX - MIN + 1) + MIN
return rand.nextInt(listaFotos.get(listaFotos.size()).getIdFoto() - listaFotos.get(0).getIdFoto() +1 ) + listaFotos.get(0).getIdFoto();
   }


photo.class
Code:
        @ManyToOne
   @JoinColumn(name="IDALBUM")
   private Album album;


albumDAOImpl.class
Code:
   @SuppressWarnings("unchecked")
   public List<Album> getAlbumnes(Integer idAsociacion,boolean esMiembro) throws DataAccessException{
      logger.trace("AlbumDAOImpl.getAlbumnes");
      
      Criteria criteria=getSession().createCriteria(Album.class);
      
      if(esMiembro==false)
         criteria.add(Restrictions.eq("privado",false));
      
      Criteria criteriaAso=criteria.createCriteria("asociacion");
      criteriaAso.add(Restrictions.eq("idAsociacion",idAsociacion));
      
      return (List<Album>)criteria.list();
   }


Really, I dont understand because in EAGER collection return four albums. Someone can me explain this behavior?

Kinds regards.


Top
 Profile  
 
 Post subject: Re: Eager collection made reciprocal select.
PostPosted: Mon Jun 11, 2012 1:02 pm 
Beginner
Beginner

Joined: Mon Jun 04, 2012 12:31 pm
Posts: 20
Is it returning the same data twice?


Top
 Profile  
 
 Post subject: Re: Eager collection made reciprocal select.
PostPosted: Mon Jun 11, 2012 1:45 pm 
Newbie

Joined: Wed Jan 12, 2011 1:15 pm
Posts: 11
Exactly, the referenceĀ“s object is the same, if I add another photo in any Album, then returning 2 Album A cloned and 3 Album B cloned


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