-->
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: Help with defining a Criteria based query?
PostPosted: Wed Jul 01, 2009 10:46 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
I'm having problems defining a Criteria based query. Listed below are the classes involved...
Code:
   public class AppUser extends  IDEntity {
      private int ID;
      ....
   }

   public class FullExpert extends AbstractExpert {
      private in AppUserID
      private Set<AppUser> Owners = new LinkedHashSet<AppUser>();
      ....
   }

   private class FullExpertise extends AbstractExpertise {
      private FullExpert Expert
      ....
   }



Basically I want to retrieve a list of all FullExpertise instances where a given integer ID matches 'FullExpertise.expert.appUserID' or matches one of the AppUser instances in the 'FullExpertise.expert.owners' set. The HQL code would be something like...
Code:
      select e from FullExpertise e join e.expert.owners owner where e.expert.appUserID = ? or owner.ID = ?";


For reasons too complicated to explain I have to query this using Criteria. Can anybody help me define this?


Top
 Profile  
 
 Post subject: Re: Help with defining a Criteria based query?
PostPosted: Wed Jul 01, 2009 1:00 pm 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
At a more basic level I can't even get the HQL to work. So far I'm using...
Code:
select e from FullExpertise as e
         inner join e.expert as x
         inner join x.owners as w
         where x.appUserID = ? or w.ID = ?


This returns zero records when I know it should return 8 records.

If I use...
Code:
from FullExpertise as e where e.expert.appUserID = ?

... this returns 4 records, so it's obviously something wrong with my join logic on the 'FullExpertise.expert.owners' part.

Here are snippets from the entity mappings....
Code:

    <class name="com.eis.knowledge.expertise.search.FullExpertise" table="expertise">
        <id name="ID" type="java.lang.Integer" unsaved-value="-1">
            <column name="ExpertiseIntID" />
            <generator class="native" />
        </id>
        <many-to-one name="expert" class="com.eis.knowledge.expert.definition.FullExpert" fetch="join" lazy="false">
            <column name="ExpertIntID" not-null="true" />
        </many-to-one>


    <class name="com.eis.knowledge.expert.definition.FullExpert" table="skap_expert">
        <id name="ID" type="java.lang.Integer" unsaved-value="-1">
            <column name="ExpertIntID" />
            <generator class="native" />
        </id>
        <property name="appUserID" type="java.lang.Integer">
            <column name="SkapUserIntID" unique="true" />
        </property>
        <set name="owners" inverse="true" table="expert_owner">
            <key>
                <column name="ExpertIntID" not-null="true" />
            </key>
            <many-to-many column="SkapUserIntID" class="com.eis.appuser.AppUser" order-by="SkapUserExternalID"/>
        </set>


    <class name="com.eis.appuser.AppUser" table="skap_user_extra">
        <id name="ID" type="java.lang.Integer" unsaved-value="-1">
            <column name="SkapUserIntID" />
            <generator class="native" />
        </id>



Any ideas?


Top
 Profile  
 
 Post subject: Re: Help with defining a Criteria based query?
PostPosted: Wed Jul 01, 2009 1:13 pm 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
This HQL works...
Code:
   select e from FullExpertise as e left join e.expert as x left join x.owners as w where x.appUserID = ? or w.ID = ?


... but I'd still like to have a Criteria based equivalent. Any helpers?


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.