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.  [ 5 posts ] 
Author Message
 Post subject: Help filterying composite-element with Criteria
PostPosted: Mon Nov 17, 2008 11:33 pm 
Newbie

Joined: Mon Nov 17, 2008 11:22 pm
Posts: 3
Hello,

I have a class that is using a composite-element for a many-to-many relationship with an extra column:

class Product {
productId;
ICollection<AditionalPropertyProduct> adProps;
}

class AditionalPropertyProduct {
value;
Product prod;
AditionalProperty prop;
}

class AditionalProperty {
code;
description;
}

Now I have to search those products that has some specific values for some specific adition property.

the resulting query should be something like
select * from Product where exists (select * from Product.adProps ad where ad.prop.code='MyCustomProp' and ad.value='20')

I tried different combinations like detached queries (getting a "No persister for") like Explresion.SQL in the ICriteria with no luck.

Is there anyone that faced this problem already?

Thanks,
Fernando


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 3:48 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have you tried

select p from Product p join p.adProps ad
where ad.prop.code='MyCustomProp' and ad.value='20'

Can you post the mappings ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 8:14 am 
Newbie

Joined: Mon Nov 17, 2008 11:22 pm
Posts: 3
This is the mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="" assembly="">

<class name="PropiedadDTO" table="PROPIEDADES">

<id name="Id" column="id_prop" type="Int32" unsaved-value="-1">
<generator class="identity" />
</id>
<property name="Titulo" column="titulo" type="String" />

<set name="VariablesAdicionales" table="PROPS_VAR_ADIC" lazy="false" fetch="join" cascade="none">
<key column="id_prop"/>
<composite-element class="VarAdicPropiedadDTO">
<parent name="Propiedad"/>
<property name="Valor" column="valor" type="String"/>
<many-to-one name="VariableAdicional" column="cod_var_adic"/>
</composite-element>
</set>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 11:26 pm 
Newbie

Joined: Mon Nov 17, 2008 11:22 pm
Posts: 3
Does anyone faced this problem?

Making an "exists" clause using an ICriteria object and the exists should filter the data?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 4:38 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can perform subqueries with detached criterias:

crit.Add(Subqueries.Exists(detachedCriteria);

What have you tried so far ? Post the criterias and the exceptions.

_________________
--Wolfgang


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