Hi,
I have a problem with Criteria object. No matter if I use the approach that embeds a criteria in a criteria or I use createAlias when I try to fetch something in a join table, I always get this exception:
org.hibernate.QueryException: duplicate association path
See the exemple below that comes from the hibernate documentation:
15.4. Associations
You may easily specify constraints upon related entities by navigating associations using createCriteria().
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%") )
.createCriteria("kittens")
.add( Restrictions.like("name", "F%") )
.list();
note that the second createCriteria() returns a new instance of Criteria, which refers to the elements of the kittens collection.
The following, alternate form is useful in certain circumstances.
List cats = sess.createCriteria(Cat.class)
.createAlias("kittens", "kt")
.createAlias("mate", "mt")
.add( Restrictions.eqProperty("kt.name", "mt.name") )
.list();
However, it works if only one element is fetched. Each time two criterias are fetched in the same time (say I want all kittens that are brown and all kitttens that hav a short tail), I got the exception.
Is there a way to prevent getting this exception?
Thanks.
|