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.  [ 7 posts ] 
Author Message
 Post subject: criteria's
PostPosted: Mon Sep 17, 2007 6:34 pm 
Newbie

Joined: Thu Jun 14, 2007 3:46 am
Posts: 17
Whats wrong with this:
ICriteria criteria = Session.CreateCriteria(typeof(Track));

int counter = 0;
foreach (SelectionRule selectrule in rule.Selectionrules)
{
//criteria.CreateAlias("criteria", String.Format("Crit{0}", counter));
criteria.CreateCriteria("criteria", String.Format("Crit{0}", counter))
//.CreateCriteria(String.Format("Crit{0}", counter))
.Add(Expression.IdEq(selectrule.Id));
counter++;
}

i get the follow exception:
duplicate association path: criteria
okay sure that only 1 is possible so i though using aliases but that also didn't work so how is possible to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 9:14 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
Forgive me for being too lazy to really read into this, but what are you trying to do? I'm a little confused.

Here's what I see:
Quote:
/* you create a new criteria for type Track off the session...okay */
ICriteria criteria = Session.CreateCriteria(typeof(Track));

/* looks like you want to add selection rules to the criteria based on a rules collection */
int counter = 0;
foreach (SelectionRule selectrule in rule.Selectionrules)
{
/* ignore */
//criteria.CreateAlias("criteria", String.Format("Crit{0}", counter));
/* You create a new criteria for type criteria with an alias of Crit1 [2,3,etc.] */
criteria.CreateCriteria("criteria", String.Format("Crit{0}", counter))
//.CreateCriteria(String.Format("Crit{0}", counter))
/* Match where criteria.id = selectRule.Id? */
.Add(Expression.IdEq(selectrule.Id));
/* increase counter for alias */
counter++;
}

i get the follow exception:
duplicate association path: criteria
okay sure that only 1 is possible so i though using aliases but that also didn't work so how is possible to do this?



Thoughts:
1. Question, do you have an object named criteria?
2. "duplicate association path: criteria", yes, because you are creating multiple aliases for the same type "criteria".
3. Maybe you meant something like selectRule.Criteria, {alias}
4. Perhaps we could help witha little more information about what your intent is.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 1:48 pm 
Newbie

Joined: Thu Jun 14, 2007 3:46 am
Posts: 17
okay; here is a better explanation.
I got 2 classes; 1 classes called "track" and another called "criteria"
Track has a ISet collection criteria.

for example:
of the class criteria i have the objects: a, b, c, d and of track x, y and z

x has in his collection a, b and d
y has in his collection b, c & d
z has a and c

now i want al tracks that have is al tracks with the objects b AND d in his SET

how to build this criteria?

ps; so you can see it's a many-to-many relation


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 3:39 pm 
Newbie

Joined: Thu Jun 14, 2007 3:46 am
Posts: 17
tis is the sql what i want (mysql); maybe easier to understand
Code:
select title from track t
inner join trackcriteria tc1 on t.Id = tc1.TrackId inner join criteria c1 on c1.Id = tc1.CriteriaId
inner join trackcriteria tc2 on t.Id = tc2.TrackId inner join criteria c2 on c2.Id = tc2.CriteriaId
where c1.id=19 and c2.id = 28


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 3:55 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
This is possible with Criteria using subqueries and DetachedCriteria. See this post.

Edit: actually, your example is different in two respects: first, you are only comparing on one child property, but you may need to match against all items in an arbitrarily long list (not just two as in the above linked post). The same principle should apply, though.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 5:23 pm 
Newbie

Joined: Thu Jun 14, 2007 3:46 am
Posts: 17
my code:
DetachedCriteria crit = DetachedCriteria.For(typeof(Criteria));
crit.Add(Expression.IdEq(selectrule.MainCriteria.Id));
crit.SetProjection(Projections.Property("Tracks"));

criteria.Add( Subqueries.PropertyIn("Criteria", crit) );

and de sql generated by hibernate:
SELECT this_.Id as Id14_0_, this_.Artist as Artist14_0_, this_.Title as Title14_0_, this_.Samenstelling as Samenste4_14_0_, this_.HourNumber as HourNumber14_0_, this_.Active as Active14_0_, this_.ShowInDatabase as ShowInDa7_14_0_, this_.Taal as Taal14_0_, this_.Filename as Filename14_0_, this_.CoverImage as CoverImage14_0_, this_.Tempo as Tempo14_0_, this_.IntroTempo as IntroTempo14_0_, this_.UitroTempo as UitroTempo14_0_, this_.Mood as Mood14_0_, this_.Texture as Texture14_0_, this_.CueStartTime as CueStar16_14_0_, this_.CueStartTimeNext as CueStar17_14_0_, this_.CueStartFadeIn as CueStar18_14_0_, this_.CueLengthFadeIn as CueLeng19_14_0_, this_.CueStartFadeOut as CueStar20_14_0_, this_.CueLengthFadeOut as CueLeng21_14_0_, this_.CueIntro as CueIntro14_0_, this_.CueUitro as CueUitro14_0_, this_.CueNext as CueNext14_0_, this_.CueEnd as CueEnd14_0_
FROM track this_

WHERE
this_.Id in (SELECT this_0_.Id as y0_ FROM criteria this_0_ WHERE this_0_.Id = ?p0)

and
this_.Id in (SELECT this_0_.Id as y0_ FROM criteria this_0_ WHERE this_0_.Id = ?p1); ?p0 = '33', ?p1 = '27'

He now tries to check wrong numbers so how can i go to the many-to-many mapping table?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 5:50 pm 
Newbie

Joined: Thu Jun 14, 2007 3:46 am
Posts: 17
or is it easier to create this with HQL and are there exaples?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.