-->
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: DetachedCriteria query fails but identical Criteria query ok
PostPosted: Tue Feb 27, 2007 12:05 pm 
Newbie

Joined: Sat Feb 24, 2007 10:16 pm
Posts: 4
I have been having a problem using nested criteria to place restrictions on properties of child objects. It turns out that the problem was solved when I moved from using DetachedCriteria objects to executable Criteria objects. Given the following relationship:

Code:
Class Bid {
   Item item;
}

Class Item {
   Property p1;
}


I wanted to query for all Bids with Items whose property p1 = X. I set up a simple mapping with a many-to-one reference from Bid to Item, and tried to execute the following code, which failed with a HibernateQueryException: duplicate association path:

Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Bid.class);
criteria.createCriteria("item","i").add(Restrictions.eq("p1",X));
Collection col = getHibernateTemplate.findByCriteria(criteria)


After struggling for two days, I tried the same thing with executable criteria, and succeeded:

Code:
Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Bid.class);
criteria.createCriteria("item","i").add(Restrictions.eq("p1",X));
Collection col = criteria.list();


I know that findByCriteria is a Spring function, but all it does is call DetachedCriteria.getExecutableCriteria(Session session), so I don't think it's a Spring problem.

Does anyone know why the DetachedCriteria query fails?

Thanks,
Jacob


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.