-->
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 does not work with coll. of dependent objects
PostPosted: Wed Jun 21, 2006 10:51 am 
Newbie

Joined: Wed Jun 21, 2006 10:18 am
Posts: 1
Hi,

I am experiensing a problem using Criteria Queries with a collection of dependent objects.

I have an entity class EmailDialog that contains a collection of UserEmailDialog objects (field participants). UserEmailDialog is an association class that represents properties of an association between Users and EmailDialogs.

Here is my mapping for class EmailDialog:

<class name="EmailDialog" table="EmailDialog">

<id name="id" type="long" column="id" unsaved-value="null" access="property">
<generator class="sequence">
<param name="sequence">emaildialog_sequence</param>
</generator>
</id>

<set name="participants" table="UserEmailDialog">
<key column="emaildialog_id" not-null="true" foreign-key="useremaildialog_emaildialog_fk"/>
<composite-element class="UserEmailDialog">
<many-to-one name="participant" class="com.fa.domain.User" column="user_id" foreign-key="useremaildialog_user_fk" not-null="true"/>
<property name="deleted" type="boolean" column="deleted" not-null="true"/>
<property name="read" type="boolean" column="read" not-null="true"/>
</composite-element>
</set>

<property name="subject" column="subject" type="string" length="300" not-null="true"/>
</class>


I am trying to use the following Criteria Query to find all EmailDialogs in which a particular user participate:
Criteria crit = session.createCriteria(EmailDialog.class).createCriteria("participants").createCriteria("participant").add(Restrictions.eq("id", userId));

I am getting the following exception:
org.hibernate.MappingException: collection was not an association: com.fa.domain.mailbox.EmailDialog.participants.

Can anything be done to get the Criteria Query working without making UserEmailDialog a separate entity class? Is there any way to use such collections of dependent objects in Criteria Queries?

Many thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 9:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Try using createAlias instead of createCriteria.
Code:
Criteria crit = session.createCriteria(EmailDialog.class)
  .createAlias("Participants", "set")
  .createAlias("set.Participant", "part")
  .add(Restrictions.eq("part.Id", userId));
By and large, you don't need to use subcriteria unless you want to use each criteria separately. It is usually as effective and more efficient to use just the original Criteria object.

_________________
Code tags are your friend. Know them and use them.


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.