-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-many associations in criteria queries
PostPosted: Thu Jul 14, 2005 4:09 pm 
Newbie

Joined: Thu Jul 14, 2005 3:11 pm
Posts: 1
Hibernate 3.0.5


Hi,
I have a uni-directional many-many relatonship using join-table defined in the following way.

Client and Module have many-to-many relation via client_modules table.

<class name="Client"..
...
<set name="assignedModules" lazy="true" table="client_modules">
<key column="client_id" not-null="true"/>
<composite-element class="ClientModule">
<many-to-one name="module" class="Module" column="client_module_id" not-null="true"/>
<property name="allBranches" type="java.lang.Boolean" column="allbranches" not-null="true"/>
</composite-element>
</set>
..
</Class>

In my criteria query, i need to add restriction looking for a particular module id. I tried to create alias using createAlias and use it like

criteria.createAlias("client.assignedModules", "myClientModule")
...
criteria.add(Expression.eq("myClientModule.module.id", new Integer(2)))
..

I am getting
org.hibernate.MappingException: collection was not an association: Client.assignedModules

I partially understand why i am getting this error. But, couldn't figure out how to overcome this.

So, how do i add search criteria for elements in a collection of components?

Thanks for reading the post. Any ideas for a newbie, please?

Ravi


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.