I assume that you are using the criteria API.
If you check the source code for Hibernate, you may find the problem here:
CriteriaQueryTranslator#createAssociationPathCriteriaMap() private void createAssociationPathCriteriaMap() { Iterator iter = rootCriteria.iterateSubcriteria(); while ( iter.hasNext() ) { CriteriaImpl.Subcriteria crit = ( CriteriaImpl.Subcriteria ) iter.next(); String wholeAssociationPath = getWholeAssociationPath( crit ); Object old = associationPathCriteriaMap.put( wholeAssociationPath, crit ); if ( old != null ) { throw new QueryException( "duplicate association path: " + wholeAssociationPath ); } int joinType = crit.getJoinType(); old = associationPathJoinTypesMap.put( wholeAssociationPath, new Integer( joinType ) ); if ( old != null ) {
I am using Hibernate 3.3.2.
What happens inside is that when you add Criteria to your root, Criteria Hibernate creates a SubCriteria and then populates the Map (check the code below) with all the paths you are trying to use, and if it detects duplication, that will throw an exception.
So, for example, if you try to join: entity0.entity1 , and later you try to join this, you will get an Exception . It will not work even with an alias, because Hibernate does not care about them here.
You can get around this if you don't join something twice, or you can use HQL / JPQL. You can check newer versions of Hibernate, but I'm not sure if they fixed this quasi error.
source share