60
60
* </ol>
61
61
*
62
62
* @author Steve Ebersole
63
+ * @author Chris Cranford
63
64
*/
64
65
public class LoadQueryJoinAndFetchProcessor {
65
66
private static final Logger LOG = CoreLogging .logger ( LoadQueryJoinAndFetchProcessor .class );
@@ -182,7 +183,8 @@ private void renderEntityJoin(Join join, JoinFragment joinFragment) {
182
183
addJoins (
183
184
join ,
184
185
joinFragment ,
185
- joinable
186
+ joinable ,
187
+ null
186
188
);
187
189
}
188
190
@@ -223,8 +225,8 @@ else if ( StringHelper.isNotEmpty( withClause ) && StringHelper.isNotEmpty( filt
223
225
private void addJoins (
224
226
Join join ,
225
227
JoinFragment joinFragment ,
226
- Joinable joinable ) {
227
-
228
+ Joinable joinable ,
229
+ String joinConditions ) {
228
230
final String rhsTableAlias = aliasResolutionContext .resolveSqlTableAliasFromQuerySpaceUid (
229
231
join .getRightHandSide ().getUid ()
230
232
);
@@ -239,10 +241,18 @@ private void addJoins(
239
241
throw new IllegalStateException ( "QuerySpace with that UID was not yet registered in the AliasResolutionContext" );
240
242
}
241
243
244
+ String otherConditions = join .getAnyAdditionalJoinConditions ( rhsTableAlias );
245
+ if ( !StringHelper .isEmpty ( otherConditions ) && !StringHelper .isEmpty ( joinConditions ) ) {
246
+ otherConditions += " and " + joinConditions ;
247
+ }
248
+ else if ( !StringHelper .isEmpty ( joinConditions ) ) {
249
+ otherConditions = joinConditions ;
250
+ }
251
+
242
252
// add join fragments from the collection table -> element entity table ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
243
253
final String additionalJoinConditions = resolveAdditionalJoinCondition (
244
254
rhsTableAlias ,
245
- join . getAnyAdditionalJoinConditions ( rhsTableAlias ) ,
255
+ otherConditions ,
246
256
joinable ,
247
257
getJoinedAssociationTypeOrNull ( join )
248
258
);
@@ -354,7 +364,8 @@ private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
354
364
addJoins (
355
365
join ,
356
366
joinFragment ,
357
- (Joinable ) rightHandSide .getCollectionPersister ()
367
+ (Joinable ) rightHandSide .getCollectionPersister (),
368
+ null
358
369
);
359
370
}
360
371
@@ -378,21 +389,26 @@ private void renderManyToManyJoin(
378
389
if ( StringHelper .isEmpty ( entityTableAlias ) ) {
379
390
throw new IllegalStateException ( "Collection element (many-to-many) table alias cannot be empty" );
380
391
}
392
+
393
+ final String manyToManyFilter ;
381
394
if ( JoinDefinedByMetadata .class .isInstance ( join ) &&
382
395
CollectionPropertyNames .COLLECTION_ELEMENTS .equals ( ( (JoinDefinedByMetadata ) join ).getJoinedPropertyName () ) ) {
383
396
final CollectionQuerySpace leftHandSide = (CollectionQuerySpace ) join .getLeftHandSide ();
384
397
final CollectionPersister persister = leftHandSide .getCollectionPersister ();
385
- final String manyToManyFilter = persister .getManyToManyFilterFragment (
398
+ manyToManyFilter = persister .getManyToManyFilterFragment (
386
399
entityTableAlias ,
387
400
buildingParameters .getQueryInfluencers ().getEnabledFilters ()
388
401
);
389
- joinFragment .addCondition ( manyToManyFilter );
402
+ }
403
+ else {
404
+ manyToManyFilter = null ;
390
405
}
391
406
392
407
addJoins (
393
408
join ,
394
409
joinFragment ,
395
- (Joinable ) entityPersister
410
+ (Joinable ) entityPersister ,
411
+ manyToManyFilter
396
412
);
397
413
}
398
414
0 commit comments