Skip to content
Merged
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 @@ -183,18 +183,13 @@ private static void entityToString(
JsonAppender appender) {
final EntityIdentifierMapping identifierMapping = entityType.getIdentifierMapping();
appender.trackingEntity( value, entityType, shouldProcessEntity -> {
appender.append( "{\"" ).append( identifierMapping.getAttributeName() ).append( "\":" );
entityIdentifierToString( value, identifierMapping, options, appender );
if ( shouldProcessEntity ) {
appender.append( "{\"" ).append( identifierMapping.getAttributeName() ).append( "\":" );
entityIdentifierToString( value, identifierMapping, options, appender );
// if it wasn't already encountered, append all properties
managedTypeToString( value, entityType, options, appender, ',' );
appender.append( '}' );
}
else {
// if it was already encountered, only append the identity string
appender.append( '\"' ).append( entityType.getEntityName() ).append( '#' );
entityIdentifierToString( value, identifierMapping, options, appender );
appender.append( '\"' );
}
appender.append( '}' );
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ public void testCompanyFetchEmployees(SessionFactoryScope scope) {
employees.forEach( employee -> {
assertDoesNotThrow( () -> UUID.fromString( employee.get( "uniqueIdentifier" ).asText() ) );
assertThat( employee.get( "firstName" ).textValue() ).startsWith( "Ma" );
assertThat( employee.get( "company" ).textValue() ).isEqualTo( Company.class.getName() + "#1" );
final JsonNode company = employee.get( "company" );
assertThat( company.get( "id" ).intValue() ).isEqualTo( 1 );
assertThat( company.properties().stream().map( Map.Entry::getKey ) )
.containsOnly( "id" ); // circular relationship
} );
}
catch (JsonProcessingException e) {
Expand Down Expand Up @@ -348,8 +351,10 @@ public void testComplexInheritance(SessionFactoryScope scope) {
assertThat( cat.isObject() ).isTrue();
assertThat( cat.get( "id" ).intValue() ).isEqualTo( 2 );
assertThat( cat.get( "description" ).textValue() ).isEqualTo( "Gatta" );
assertThat( cat.get( "owner" ).isTextual() ).isTrue(); // circular relationship
assertThat( cat.get( "owner" ).textValue() ).isEqualTo( Human.class.getName() + "#1" );
final JsonNode owner = cat.get( "owner" );
assertThat( owner.get( "id" ).intValue() ).isEqualTo( 1 );
assertThat( owner.properties().stream().map( Map.Entry::getKey ) )
.containsOnly( "id" ); // circular relationship

final JsonNode nickNames = jsonNode.get( "nickNames" );
assertThat( nickNames.isArray() ).isTrue();
Expand Down