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: Composite Elements - collection was not an association
PostPosted: Tue Sep 02, 2008 7:10 am 
Newbie

Joined: Tue Sep 02, 2008 7:02 am
Posts: 2
Hi I have an application that requires complex and dynamic filtering of entities and as a result I have started using the Crieria API as it enables me to combine criteria and generally to build dynamic queries very nicely. However, I have hit a serious problem.

Some of the database structures that I am forced to use are making it necessary to map associations as composite-elements e.g.

<class name="Item" table="RM_Item">
<id name="Id" access="field.camelcase-underscore" >
<column name="ItemID" sql-type="int" not-null="true"/>
<generator class="assigned" />
</id>
<set name="ItemAccesses" lazy="true" table="RM_ItemAccess">
<key column="ItemID"/>
<composite-element class="ItemAccess">
<parent name="Item"/>
<many-to-one name="Group" cascade="none" class="ResourceGroup" column="GroupID" not-null="true" />
<property name="AccessRight" column="AccessRights" not-null="true"/>
</composite-element>
</set>
</class>

As I understand it this means that I cannot use CreateCriteria to model a join to the associated collection using the Criteria API e.g.

var items = _session.CreateCriteria(typeof (IItem))
.CreateCriteria("ItemAccesses")
.Add(Expression.Eq("AccessRight", 2))
.List<IItem>();

This will not work giving me the error "collection was not an association". I can easily write this query in HQL but that will make a lot of other things harder.

What can i do? Is it possible to convert from HQL to Criteria? Is there some other way I can do the mapping to avoid the composite-element so that I can use the Criteria API.

Any help gratefully received.

Julian Jelfs.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 1:27 am 
Newbie

Joined: Mon Dec 01, 2008 1:16 am
Posts: 1
Location: Southern California, USA
I'm running into the same difficulty, with a collection of java.lang.String objects (alternate names for an entity). I noticed that the first question of the Advanced Problems FAQ recommends either using HQL or submitting a patch.

Since, like the original poster, I would find it very inconvenient to use HQL for program-generated queries, I'd like to work on a patch. I've found the place where the exception is generated, but my DB experience is low enough that I'm having trouble figuring out how to proceed. Would anyone have advice on how to extend the existing code to handle this sort of query, where to look for similar code, or any other helpful comments?

I suppose I could create another entity class, a String with an ID, and make it a collection of those. Seems like a kluge, though, and I'd rather have it work right.


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.