-
Notifications
You must be signed in to change notification settings - Fork 215
DTO joins support issues #2761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.10.x
Are you sure you want to change the base?
DTO joins support issues #2761
Changes from 6 commits
37fa871
b7c27ca
c526c08
9790cf9
78d0df4
3fee2bc
d3744c0
e7a0a4a
37da946
a8c0ce5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.StringJoiner; | ||
import java.util.UUID; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
|
@@ -71,6 +72,7 @@ public final class SqlResultEntityTypeMapper<RS, R> implements SqlTypeMapper<RS, | |
private final SqlJsonColumnReader<RS> jsonColumnReader; | ||
private final DataConversionService conversionService; | ||
private final BiFunction<RuntimePersistentEntity<Object>, Object, Object> eventListener; | ||
private final boolean isDto; | ||
private boolean callNext = true; | ||
|
||
/** | ||
|
@@ -86,8 +88,9 @@ public SqlResultEntityTypeMapper( | |
String prefix, | ||
@NonNull RuntimePersistentEntity<R> entity, | ||
@NonNull ResultReader<RS, String> resultReader, | ||
@Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) { | ||
this(entity, resultReader, Collections.emptySet(), prefix, jsonColumnReader, conversionService, null); | ||
@Nullable SqlJsonColumnReader<RS> jsonColumnReader, | ||
DataConversionService conversionService) { | ||
this(entity, resultReader, Collections.emptySet(), prefix, jsonColumnReader, conversionService, null, false); | ||
} | ||
|
||
/** | ||
|
@@ -104,7 +107,7 @@ public SqlResultEntityTypeMapper( | |
@NonNull ResultReader<RS, String> resultReader, | ||
@Nullable Set<JoinPath> joinPaths, | ||
@Nullable SqlJsonColumnReader<RS> jsonColumnReader, DataConversionService conversionService) { | ||
this(entity, resultReader, joinPaths, null, jsonColumnReader, conversionService, null); | ||
this(entity, resultReader, joinPaths, null, jsonColumnReader, conversionService, null, false); | ||
} | ||
|
||
/** | ||
|
@@ -116,14 +119,17 @@ public SqlResultEntityTypeMapper( | |
* @param jsonColumnReader The json column reader | ||
* @param loadListener The event listener | ||
* @param conversionService The conversion service | ||
* @param isDto Whether reading/mapping DTO projection | ||
*/ | ||
public SqlResultEntityTypeMapper( | ||
@NonNull RuntimePersistentEntity<R> entity, | ||
@NonNull ResultReader<RS, String> resultReader, | ||
@Nullable Set<JoinPath> joinPaths, | ||
@Nullable SqlJsonColumnReader<RS> jsonColumnReader, | ||
@Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, DataConversionService conversionService) { | ||
this(entity, resultReader, joinPaths, null, jsonColumnReader, conversionService, loadListener); | ||
@Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> loadListener, | ||
DataConversionService conversionService, | ||
boolean isDto) { | ||
this(entity, resultReader, joinPaths, null, jsonColumnReader, conversionService, loadListener, isDto); | ||
} | ||
|
||
/** | ||
|
@@ -136,14 +142,17 @@ public SqlResultEntityTypeMapper( | |
* @param jsonColumnReader The json column reader | ||
* @param eventListener The event listener used for trigger post load if configured | ||
* @param conversionService The conversion service | ||
* @param isDto Whether reading/mapping DTO projection | ||
*/ | ||
private SqlResultEntityTypeMapper( | ||
@NonNull RuntimePersistentEntity<R> entity, | ||
@NonNull ResultReader<RS, String> resultReader, | ||
@Nullable Set<JoinPath> joinPaths, | ||
String startingPrefix, | ||
@Nullable SqlJsonColumnReader<RS> jsonColumnReader, | ||
DataConversionService conversionService, @Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> eventListener) { | ||
DataConversionService conversionService, | ||
@Nullable BiFunction<RuntimePersistentEntity<Object>, Object, Object> eventListener, | ||
boolean isDto) { | ||
this.conversionService = conversionService; | ||
ArgumentUtils.requireNonNull("entity", entity); | ||
ArgumentUtils.requireNonNull("resultReader", resultReader); | ||
|
@@ -160,6 +169,7 @@ private SqlResultEntityTypeMapper( | |
this.joinPaths = Collections.emptyMap(); | ||
} | ||
this.startingPrefix = startingPrefix; | ||
this.isDto = isDto; | ||
} | ||
|
||
@Override | ||
|
@@ -622,6 +632,11 @@ private <K> K triggerPostLoad(RuntimePersistentEntity<?> persistentEntity, K ent | |
private <K> Object readEntityId(RS rs, MappingContext<K> ctx) { | ||
RuntimePersistentProperty<K> identity = ctx.persistentEntity.getIdentity(); | ||
if (identity == null) { | ||
// DTO might not have ID mapped, and in this case to maintain relation | ||
// we set random UUID as id to be able to read and make relation | ||
if (isDto) { | ||
return UUID.randomUUID(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this will work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there is a test that covers that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand, don't know if could break some user case, all tests we have are passing. |
||
} | ||
return null; | ||
} | ||
if (identity instanceof Embedded) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.