Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
*
* @author Mark Paluch
* @author Jens Schauder
* @author Ki Hoon You
*/
class MappingJdbcConverterUnitTests {

Expand Down Expand Up @@ -187,6 +188,38 @@ void readByteArrayToNestedUuidWithCustomConverter() {

}

@Test // GH-2201
void shouldReadEntityWithClassBasedCompositeIdUsingReadAndResolve() {

// This test verifies that ResolvingRelationalPropertyValueProvider.potentiallyAppendIdentifier
// correctly handles embedded composite IDs without throwing "Cannot obtain ColumnInfo for embedded path"
RowDocument rowdocument = new RowDocument(Map.of("UID", "1", "TID", "2", "ALIAS", "test-alias"));

TenantUserWithClassId result = converter.readAndResolve(TenantUserWithClassId.class, rowdocument);

assertThat(result).isNotNull();
assertThat(result.id).isNotNull();
assertThat(result.id.uid).isEqualTo("1");
assertThat(result.id.tid).isEqualTo("2");
assertThat(result.alias).isEqualTo("test-alias");
}

@Test // GH-2201
void shouldReadEntityWithRecordBasedCompositeIdUsingReadAndResolve() {

// This test verifies that ResolvingRelationalPropertyValueProvider.potentiallyAppendIdentifier
// correctly handles embedded composite IDs without throwing "Cannot obtain ColumnInfo for embedded path"
RowDocument rowdocument = new RowDocument(Map.of("UID", "1", "TID", "2", "ALIAS", "test-alias"));

TenantUserWithRecordId result = converter.readAndResolve(TenantUserWithRecordId.class, rowdocument);

assertThat(result).isNotNull();
assertThat(result.id()).isNotNull();
assertThat(result.id().uid()).isEqualTo("1");
assertThat(result.id().tid()).isEqualTo("2");
assertThat(result.alias()).isEqualTo("test-alias");
}

private static void checkReadConversion(SoftAssertions softly, MappingJdbcConverter converter, String propertyName,
Object expected) {

Expand Down Expand Up @@ -279,6 +312,19 @@ private record Referenced(@Id Long id) {
private record ReferencedByUuid(@Id UUID id) {
}

// GH-2201: Test entities for composite ID issue
static class TenantUserWithClassId {
@Id
TenantUserID id;
String alias;
}

record TenantUserID(String uid, String tid) {
}

record TenantUserWithRecordId(@Id TenantUserID id, String alias) {
}

static class ByteArrayToUuid implements Converter<byte[], UUID> {
@Override
public UUID convert(byte[] source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,14 +1214,33 @@ public boolean hasNonEmptyValue(RelationalPersistentProperty property) {
@Override
public Object getValue(AggregatePath path) {

Object value = document.get(path.getColumnInfo().alias().getReference());
// Embedded paths (e.g., composite ids) cannot have a single ColumnInfo
// Return null as embedded values are handled through their individual properties
if (path.isEmbedded()) {
return null;
}

return value;
return document.get(path.getColumnInfo().alias().getReference());
}

@Override
public boolean hasValue(AggregatePath path) {

// Embedded paths (e.g., composite ids) cannot have a single ColumnInfo
// Check if any of the embedded properties have values
if (path.isEmbedded()) {
RelationalPersistentEntity<?> leafEntity = path.getLeafEntity();
if (leafEntity != null) {
for (RelationalPersistentProperty property : leafEntity) {
AggregatePath propertyPath = path.append(property);
if (hasValue(propertyPath)) {
return true;
}
}
}
return false;
}

Object value = document.get(path.getColumnInfo().alias().getReference());

if (value == null) {
Expand All @@ -1238,6 +1257,21 @@ public boolean hasValue(AggregatePath path) {
@Override
public boolean hasNonEmptyValue(AggregatePath path) {

// Embedded paths (e.g., composite ids) cannot have a single ColumnInfo
// Check if any of the embedded properties have non-empty values
if (path.isEmbedded()) {
RelationalPersistentEntity<?> leafEntity = path.getLeafEntity();
if (leafEntity != null) {
for (RelationalPersistentProperty property : leafEntity) {
AggregatePath propertyPath = path.append(property);
if (hasNonEmptyValue(propertyPath)) {
return true;
}
}
}
return false;
}

if (!hasValue(path)) {
return false;
}
Expand Down