HHH-6405 setFetchMode ignored for some association types when using criteria queries

Re-unifie the two methods getJoinType in the CriteriaJoinWalker, using if/else to delegate to the correct super.getJoinType(...) method as appropriate.  This allows the proper handling for setFetchMode specified in the criteria translator to be applied correctly.
This commit is contained in:
David Mansfield 2011-07-12 11:13:15 -04:00 committed by Steve Ebersole
parent ed0a9fbc00
commit f12f2324c6
1 changed files with 40 additions and 24 deletions

View File

@ -142,21 +142,23 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
String[] lhsColumns,
final boolean nullable,
final int currentDepth) throws MappingException {
JoinType ret;
if ( translator.isJoin( path.getFullPath() ) ) {
return translator.getJoinType( path.getFullPath() );
ret = translator.getJoinType( path.getFullPath() );
}
else {
if ( translator.hasProjection() ) {
return JoinType.NONE;
ret = JoinType.NONE;
}
else {
FetchMode fetchMode = translator.getRootCriteria().getFetchMode( path.getFullPath() );
if ( isDefaultFetchMode( fetchMode ) ) {
if ( persister != null ) {
if ( isJoinFetchEnabledByProfile( persister, path, propertyNumber ) ) {
return getJoinType( nullable, currentDepth );
ret = getJoinType( nullable, currentDepth );
}
else {
return super.getJoinType(
ret = super.getJoinType(
persister,
path,
propertyNumber,
@ -171,16 +173,31 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
}
}
else {
if ( fetchMode == FetchMode.JOIN ) {
isDuplicateAssociation( lhsTable, lhsColumns, associationType ); //deliberately ignore return value!
return getJoinType( nullable, currentDepth );
ret = super.getJoinType(
associationType,
metadataFetchMode,
path,
lhsTable,
lhsColumns,
nullable,
currentDepth,
metadataCascadeStyle
);
}
}
else {
return JoinType.NONE;
if ( fetchMode == FetchMode.JOIN ) {
isDuplicateAssociation( lhsTable, lhsColumns, associationType ); //deliberately ignore return value!
ret = getJoinType( nullable, currentDepth );
}
else {
ret = JoinType.NONE;
}
}
}
}
return ret;
}
protected JoinType getJoinType(
@ -192,18 +209,17 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
boolean nullable,
int currentDepth,
CascadeStyle cascadeStyle) throws MappingException {
return ( translator.isJoin( path.getFullPath() ) ?
translator.getJoinType( path.getFullPath() ) :
super.getJoinType(
return getJoinType(
null,
path,
-1,
associationType,
config,
path,
cascadeStyle,
lhsTable,
lhsColumns,
nullable,
currentDepth,
cascadeStyle
)
currentDepth
);
}