Criteria API: Don't throw duplicate association path

Description

Criteria.createCriteria(path) throws org.hibernate.QueryException: duplicate association path when we try to create another criteria with the same path.

That may seem reasonable, however, imagine following situation:

  • Criteria are flexible so you can have some code handling restrictions and some code handling ordering by some "query metadata" provided to the DAO method.

  • Say you are filtering for a value under some association path 'A' - so you would need subcriteria on 'A' and add a restriction to it. You are sorting according to the association path 'A' so you need the same subcriteria. But you handle setup of sorting in a different place in the code so you naively invoke criteria.createCriteria and get "org.hibernate.QueryException: duplicate association path"

It would be better if Hibernate looks through the set of subcriterias it has (in CriteriaImpl) and returns the one with the same association path.

I guess they would need to be of the same join type...

Activity

Show:

Brett Meyer May 31, 2016 at 7:37 PM

Hey , we've instead focused on JPA's Criteria API. Now that hibernate-core and hibernate-entitymanager have merged together, it should be easier to use:

http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#criteria

Greg Chabala May 31, 2016 at 7:33 PM

@brmeyer if the Criteria API is deprecated, what is its replacement?

Brett Meyer December 19, 2013 at 6:27 PM

The Criteria API is considered deprecated

Out of Date

Details

Assignee

Reporter

Priority

Created December 20, 2012 at 7:45 PM
Updated May 31, 2016 at 7:37 PM
Resolved December 19, 2013 at 6:27 PM