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: Composite-Element and Criteria Queries
PostPosted: Tue May 27, 2008 7:35 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
Hibernate version:
1.2.0

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" assembly="Domain" namespace="Domain.Entities">
   <class name="Person" table="Person">
      <id column="Id" name="Id" unsaved-value="00000000-0000-0000-0000-000000000000" access="nosetter.pascalcase-m-underscore">
         <generator class="guid.comb" />
      </id>
    <bag access="field.pascalcase-m-underscore" name="Fields" table="PersonFields" lazy="true" cascade="save-update">
      <key column="PersonId"/>
      <composite-element class="Domain.Entities.FilledField, Domain">
        <property name="Value" column="Value" type="String" length="255" not-null="false"/>
        <many-to-one name="Field" class="Domain.Entities.Field, Domain" column="FieldId" not-null="true"/>
      </composite-element>
    </bag>
   </class>
</hibernate-mapping>


In order to query the fields property of the class person I can write the following hql:

Code:
select p from Person p join p.Fields flds where 'someValue' = flds.Value


Is it possible to write something similar with Criterias ? When you try to call CreateCriteria on a criteria based on person you get an 'Not an association' error.

For example:
Code:
                        ICriteria criteria = session.CreateCriteria(typeof(Person));
                        criteria.Add("Fields").Add(Expression.Eq("Value", "someValue"));


I've tried several other things as well, but with the same outcome.

I've found a topic about this on the Hibernate forum, but with no answer. http://forum.hibernate.org/viewtopic.php?t=943792


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 29, 2008 3:21 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
*bump*


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 2:28 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Hi,
you can add a subcriteria to the criteria to fetch the association:

Code:
ICriteria criteria = session.CreateCriteria(typeof(Person));
                        criteria.CreateCriteria("Fields").Add(Expression.Eq("Value", "someValue"));


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 4:11 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
That would be true if it was a 'normal' association, since it's with composite-element it's not a 'normal' association. Executing the query like that will throw an exception stating that Fields is not an association.


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.