-->
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.  [ 1 post ] 
Author Message
 Post subject: Problem with Hibernate Criteria and "nullable=false"
PostPosted: Thu Oct 29, 2009 6:53 am 
Newbie

Joined: Fri Sep 11, 2009 10:15 am
Posts: 8
Hi,

i am using Hibernate Criteria with Query by Example and property "nullable=false" for the associations inside
my Entities. The generated SQL query is not the one i expected

Query generated by Hibernate
Code:
select
    this_.bp_personenid as bp1_5_1_
    from
        personen this_
    left outer join
        personenstichworte personenst1_
            on this_.bp_personenid=personenst1_.bp_personenid
    where
        (
            personenst1_.bp_personenid=?
        )
        and (
            1=1
        )


Hibernate adds the bp_personenid property to the where clause. This behaviour only occurs when nullable is set to "false". Is there any possibility to prevent Hibernate from adding bp_personenid to the query? (I have already tested Example.create(personenStichwort).excludeProperty("bp_personenid"))

Here are my Entity + Dao - Classes:

Person.java:
Code:
@Entity @Table(name="personen")
public class Person {
   
   @Id
   private Integer bp_personenid;
   
   @OneToMany(fetch=FetchType.EAGER)
   @JoinColumn(name="bp_personenid", nullable=false)
   @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN})
   private Set<PersonenStichwort> personenStichworte = new HashSet<PersonenStichwort>();
   
   public Set<PersonenStichwort> getPersonenStichworte() {
      return personenStichworte;
   }


PersonenStichwort.java:
Code:
@Entity
@Table(name="personenstichworte")
public class PersonenStichwort {

   @Id
   private Integer bp_personenid;
   private String stichwort;
   @Version @Generated(GenerationTime.ALWAYS) @Temporal(TemporalType.TIMESTAMP)
   private Date la;
   
   public String getStichwort() {
      return stichwort;
   }
   
   public void setStichwort(String stichwort) {
      this.stichwort = stichwort;
   }   
}


and this DAO:
Code:
public class PersonenDaoImpl extends GenericDaoImpl<Person, Integer> implements PersonenDao {

   public List<Person> findPersonen(Person person, PersonenStichwort personenStichwort) {
      Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Person.class);
   
                criteria.createCriteria("personenStichworte",CriteriaSpecification.LEFT_JOIN)
                     .add(Example.create(personenStichwort).excludeProperty("bp_personenid"));
      
      criteria.add(Example.create(person).ignoreCase().enableLike());
      criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
      
      return criteria.list();
   }

}


Best regards,

Peter


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.