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