-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria with Join
PostPosted: Tue Dec 05, 2006 12:20 pm 
Newbie

Joined: Mon Sep 18, 2006 11:36 am
Posts: 10
Location: Germany / Karlsruhe
Hi,

i've the following three classes:

    Feature - eg. "weight", "HDD Capacity", "clock rate"
    FeatureCategory - every feature is associated with one category for grouping them in the GUI. eg. "Main Features", "Misc"
    ProductType - every productType has some specific Features. "Notebook", "Display"


I'd like to recieve the featuresCategories with populated List of features. But only this features which are specified for a ProductType.
Notebook --> HDD Capacity, clock rate
Monitor --> weight

this is my idea:

Code:
Criteria crit = getSession().createCriteria(FeatureCategory.class)
   .setFetchMode("features", FetchMode.JOIN)
   .createCriteria("features")
   .createCriteria("productType")
   .add( Expression.eq("id", 10 ) );
return new HashSet(crit.list());


It works, but returns me always the whole list of features, not the specific ones for productType = 10.

Any ideas?

Thanks in Advcance,
Patrick


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 2:21 pm 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
just my two cents...
are you using any old version of hibernate. Try using Restrictions rather Expression.
Could you post your entire POJOs?

_________________
God is Love


Top
 Profile  
 
 Post subject: Criteria with Join
PostPosted: Mon Dec 11, 2006 11:56 am 
Newbie

Joined: Mon Sep 18, 2006 11:36 am
Posts: 10
Location: Germany / Karlsruhe
Hi,

i'm using hibernate 3.1.3.
here are my pojos or rather hbm's:
Feature
Code:
<hibernate-mapping package="foo.model">
    <class name="Feature">
        <id name="id" type="integer" />
   <property name="name" type="string"/>
   <many-to-one name="productType"
             class="ProductType"
             cascade="none"
             not-null="true"
             column="product_type_fk"
        lazy="false" />
        <many-to-one name="featureCategory"
       class="FeatureCategory"
            cascade="none"
            column="feature_category_fk" />
    </class>
</hibernate-mapping>


FeatureCategory
Code:
<hibernate-mapping package="foo.model">
    <class name="FeatureCategory">
        <id name="id" type="integer"/>
        <property name="name" type="string"/>
        <set name="features"
             inverse="true"
             cascade="save-update">
            <key column="feature_category_fk"/>
            <one-to-many class="Feature" />
        </set>
    </class>
</hibernate-mapping>


ProductType
Code:
<hibernate-mapping package="foo.model">
   <class name="ProductType">
      <id name="id" type="integer" />
      <property name="name" type="string" />
      <set name="features"
                        inverse="true" cascade="all-delete-orphan">
         <key column="product_type_fk" on-delete="cascade"/>
         <one-to-many class="Feature"/>
      </set>
      </class>
<hibernate-mapping>



Thanks, Patrick


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 10:16 am 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
Hi again, for your mapping resources, I've understood You have any bi-directional many-to-one association between features and featuredCategories, but I think if You want retrieve featuredCategories and constrained associated features, You just must add featuredCategories to Criteria API, instead to add features and productTypes.

Thanks

_________________
God is Love


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