@@ -125,7 +125,12 @@ private void renderJoin(Join join, JoinFragment joinFragment) {
125
125
handleCompositeJoin ( join , joinFragment );
126
126
}
127
127
else if ( EntityQuerySpace .class .isInstance ( join .getRightHandSide () ) ) {
128
- renderEntityJoin ( join , joinFragment );
128
+ // do not render the entity join for a one-to-many association, since the collection join
129
+ // already joins to the associated entity table (see doc in renderCollectionJoin()).
130
+ if ( join .getLeftHandSide ().getDisposition () != QuerySpace .Disposition .COLLECTION ||
131
+ ! CollectionQuerySpace .class .cast ( join .getLeftHandSide () ).getCollectionPersister ().isOneToMany () ) {
132
+ renderEntityJoin ( join , joinFragment );
133
+ }
129
134
}
130
135
else if ( CollectionQuerySpace .class .isInstance ( join .getRightHandSide () ) ) {
131
136
renderCollectionJoin ( join , joinFragment );
@@ -249,14 +254,14 @@ private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
249
254
rightHandSide .getCollectionPersister ()
250
255
);
251
256
252
- // if the collection being joined is a one-to-many there is actually nothing to render here - there will
253
- // be a follow-on join (rhs will have a join) for the associated entity.
257
+ // The SQL join to the "collection table" needs to be rendered.
254
258
//
255
- // otherwise the SQL join to the "collection table" needs to be rendered. In the case of a basic collection,
256
- // that's the only join needed. For many-to-many, we need to render the "collection table join" here (as
257
- // already stated), but joining to the entity element table is handled by a follow-on join for the associated
258
- // entity as discussed with regard to one-to-many
259
+ // In the case of a basic collection, that's the only join needed.
259
260
//
261
+ // For one-to-many/many-to-many, we need to render the "collection table join"
262
+ // here (as already stated). There will be a follow-on join (rhs will have a join) for the associated entity.
263
+ // For many-to-many, the follow-on join will join to the associated entity element table. For one-to-many,
264
+ // the collection table is the associated entity table, so the follow-on join will not be rendered..
260
265
261
266
if ( rightHandSide .getCollectionPersister ().isOneToMany ()
262
267
|| rightHandSide .getCollectionPersister ().isManyToMany () ) {
@@ -298,11 +303,6 @@ private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
298
303
);
299
304
}
300
305
301
- if ( rightHandSide .getCollectionPersister ().isOneToMany () ) {
302
- // as stated, nothing to do...
303
- return ;
304
- }
305
-
306
306
renderSqlJoinToCollectionTable (
307
307
aliases ,
308
308
rightHandSide ,
0 commit comments