-->
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: duplicate association path
PostPosted: Mon Dec 19, 2005 4:40 pm 
Newbie

Joined: Thu Dec 15, 2005 2:30 pm
Posts: 10
My application builds a Criteria object progammatically. Filters (where ...) are created by one routine, while ordering (sort by ...) by another. It appears that Hibernate does not allow the same association to be referenced more than once. Here is some sample code that recreates the problem:

Code:
Criteria criteria = DB.session().createCriteria(Document.class);
criteria.createCriteria("client").add(Restrictions.eq("id", 1));
criteria.createCriteria("client").addOrder(Order.asc("name"));
List list = criteria.list();


It fails with "duplicate association path: client".

So... is there any way to work around it? For instance, is there any way to progammatically extract any Criteria objects that have possibly already been created for associations out of the root Criteria object?

Thank you in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 6:38 pm 
Newbie

Joined: Mon Dec 19, 2005 3:31 pm
Posts: 3
Location: Darmstadt, Germany
Try the following:

Criteria criteria = DB.session().createCriteria(Document.class);
criteria.add(Restrictions.eq("id", 1));
criteria.addOrder(Order.asc("name"));
List list = criteria.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 1:58 am 
Newbie

Joined: Thu Dec 15, 2005 2:30 pm
Posts: 10
Codenasher, thanks for the suggestion, but I must not have made myself clear in my first post. Both "id" and "name" properties belong to a "parent" object mapped as getClient() property. Thus, I have to create a new Criterion for that association.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 4:12 am 
Newbie

Joined: Mon Dec 19, 2005 3:31 pm
Posts: 3
Location: Darmstadt, Germany
Okay sorry,

when I don't misunderstand you want to do this:

Criteria criteria = DB.session().createCriteria(Document.class);
criteria.createAlias("client", "client")
criteria.add(Restrictions.eq("client.id", 1));
criteria.addOrder(Order.asc("client.name"));
List list = criteria.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 11:12 am 
Newbie

Joined: Thu Dec 15, 2005 2:30 pm
Posts: 10
Woo-hoo! The alias did the trick! Thanks, Codenascher! You definitely earn a crewdit for this one ;)


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.