-->
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 query and <properties>
PostPosted: Tue Mar 23, 2010 9:19 am 
Newbie

Joined: Wed Mar 10, 2010 8:47 am
Posts: 4
Hi,
maybe this is a known issue or I am doing something wrong, but I haven't been able to find an appropriate topic.

I need two attributes as the target of a property-ref from another class, so I am grouping them with <properties></properties>
Code:
      <properties name="baureiheUndFabrikat" unique="true">
         <property name="baureihe" type="string" column="baureihe" length="45"></property>
         <many-to-one name="fabrikat" class="domain.Fabrikat" column="fabrikat" property-ref="name" not-found="ignore"></many-to-one>
      </properties>


I have the following Criteria query:
Code:
   @SuppressWarnings("unchecked")
   public List<Baureihe> findByExample(Baureihe baureihe, int start,
         int pageSize) {
      Criteria crt = createExampleCriteria(baureihe);
      crt.setFirstResult(start);
      crt.setMaxResults(pageSize);
      
      return crt.list();
   }

   public Integer getNumberByExample(Baureihe baureihe) {
      Criteria crt = createExampleCriteria(baureihe);
      crt.setProjection(Projections.rowCount());
      return (Integer) crt.uniqueResult();
   }
   
   private Criteria createExampleCriteria(Baureihe baureihe) {
      Example example = Example.create(baureihe).ignoreCase().enableLike(MatchMode.ANYWHERE);
      
      Criteria crt = sessionFactory.getCurrentSession().createCriteria(Baureihe.class);
      crt.add(example);
      if (baureihe.getFabrikat() != null)
         crt.createCriteria("fabrikat").add(Example.create(baureihe.getFabrikat()));
      if (baureihe.getFahrzeugtyp() != null)
         crt.createCriteria("fahrzeugtyp").add(Example.create(baureihe.getFahrzeugtyp()));
      if (baureihe.getHersteller() != null)
         crt.createCriteria("hersteller").add(Example.create(baureihe.getHersteller()));
      
      return crt;
   }


These two queries are used for filtering the results and paging.
If the "fabrikat" is set I get an error that the column "name" of "fabrikat" is unknown, but it does exist.
It works fine if I move the <many-to-one> outside of the <properties>, so the problem is only occuring when <properties> is used.
From the hibernate documentation I understand that <properties> is just a grouping and useful to have multiple properties as the target of a property-ref, exactly what I am doing.

Is the syntax of my criteria query wrong and I have to use the name of my <properties> element or is this a bug?

edit: I am using version 3.3.2 of hibernate

Thank you
Best regards
Tobias


Top
 Profile  
 
 Post subject: Re: Criteria query and <properties>
PostPosted: Thu Mar 25, 2010 3:22 am 
Newbie

Joined: Wed Mar 10, 2010 8:47 am
Posts: 4
I am really stuck on problems with the <properties> element right now. Does anybody have working examples with that?


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.