New posts for Spring and Hibernate

This commit is contained in:
2026-11-06 01:05:27 +05:30
parent 51913ad9d4
commit dc13293046
136 changed files with 5268 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# Null handling: IGNORE vs the default on a patch, and RETURN_DEFAULT on whole objects and collections
--- patch(): nullValuePropertyMappingStrategy = IGNORE, applied with a patch whose components are all null ---
before: [email protected], nickname=ash, roles=[USER], address=12 Park Road/Pune/411001
after : [email protected], nickname=ash, roles=[USER], address=12 Park Road/Pune/411001
--- replace(): the default strategy (SET_TO_NULL), same all-null patch ---
before: [email protected], nickname=ash, roles=[USER], address=12 Park Road/Pune/411001
after : email=null, nickname=null, roles=null, address=null
--- whole objects and collections: OrderMapper (default) vs LenientOrderMapper (RETURN_DEFAULT) ---
strict.toDto(null) : null
lenient.toDto(null) : OrderDto[id=null, status=null, placedAt=null, lines=null, total=null]
strict order, lines = null : lines=null
lenient order, lines = null : lines=[]
strict.toDtos(null) : null
--- the generated patch() (IGNORE): every assignment is guarded ---
public void patch(CustomerPatch patch, Customer customer) {
if ( patch == null ) {
return;
}
if ( patch.email() != null ) {
customer.setEmail( patch.email() );
}
if ( patch.nickname() != null ) {
customer.setNickname( patch.nickname() );
}
if ( patch.address() != null ) {
if ( customer.getAddress() == null ) {
customer.setAddress( new Address() );
}
addressMapper.update( patch.address(), customer.getAddress() );
}
if ( customer.getRoles() != null ) {
Set<String> set = patch.roles();
if ( set != null ) {
customer.getRoles().clear();
customer.getRoles().addAll( set );
}
}
else {
Set<String> set = patch.roles();
if ( set != null ) {
customer.setRoles( new LinkedHashSet<String>( set ) );
}
}
}