-->
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: PropertySelector OneToMany possible bug
PostPosted: Sat Mar 27, 2010 2:37 pm 
Newbie

Joined: Mon Nov 26, 2007 8:33 pm
Posts: 6
Hi people, considering I have the following code:

Entities:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Pessoa {
   
   @Id
   @SequenceGenerator(name="pessoa_seq", sequenceName="PESSOA_SEQ", allocationSize=1)
   @GeneratedValue(strategy=GenerationType.AUTO, generator="pessoa_seq")
   private Long id;
   
   @OneToMany(mappedBy="pessoa", fetch=FetchType.EAGER, cascade=CascadeType.ALL) // At this time, I want Eager fetching
    private Set<Telefone> telefones;

    // Other properties are omitted

   public Pessoa(){

   }

            // Getters and setters

   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + ((id == null) ? 0 : id.hashCode());
      return result;
   }

   @Override
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      Pessoa other = (Pessoa) obj;
      if (id == null) {
         if (other.id != null)
            return false;
      } else if (!id.equals(other.id))
         return false;
      return true;
   }


Code:
@Entity
public class Cliente extends Pessoa {
   @Temporal(TemporalType.DATE)
   private Date clienteDesde;

   // Getters and Setters omitted
}


And my DAO, supposing I'm passing a Cliente as the Generic Type:

Code:
   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
   public List<T> findByExample(T entity) {     
      Example example = Example.create(entity).ignoreCase().enableLike(MatchMode.ANYWHERE).setPropertySelector(new PropertySelector(){
          @Override
           public boolean include(Object arg0, String arg1, Type arg2){
              Sytem.out.println(arg0 + " - " + arg1 + " - " + arg2);
           }
      });
      return getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(entity.getClass()).add(example).list();
   }


Why does my include method never prints the inner OneToMany properties from Pessoa (like Set<Telefone> telefones), only the other attributes?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: PropertySelector OneToMany possible bug
PostPosted: Mon Mar 29, 2010 8:52 pm 
Newbie

Joined: Mon Nov 26, 2007 8:33 pm
Posts: 6
I've thinking about it folks, and I realized that it could be because its a constrained property with a foreign key relationship with another entity.
So, there is a good motive (if it's the case) to hibernate do that distinct treatment?
It is a good option to search for a workround for this or a I've to try another approach, witch?


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.