Thanks to visit codestin.com
Credit goes to github.com

Skip to content

@Mapping nullValuePropertyMappingStrategy = CLEAR for Collection properties #1830

@kitirisovgeorgy

Description

@kitirisovgeorgy

It's generated code:

    @Override
    public void updatedEventToIssueSummary(IssueSummary out, IssueUpdatedEvent event) {
        if ( event == null ) {
            return;
        }

        if ( out.getChecklist() != null ) {
            Collection<Checklist> collection = checklistDtoCollectionToChecklistCollection( event.getChecklist() );
            if ( collection != null ) {
                out.getChecklist().clear();
                out.getChecklist().addAll( collection );
            }
            else {
                out.setChecklist( null );
            }
        }
        else {
            Collection<Checklist> collection = checklistDtoCollectionToChecklistCollection( event.getChecklist() );
            if ( collection != null ) {
                out.setChecklist( collection );
            }
        }
...
    }
@Entity
public class IssueSummary {

...
  @OneToMany(
      cascade = CascadeType.ALL,
      orphanRemoval = true,
      fetch = FetchType.EAGER
  )
  Collection<Checklist> checklist;
}

Flow

        if ( out.getChecklist() != null ) {
            if ( collection != null ) { ... }
            else {
                out.setChecklist( null );
            }

cause exception:
Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

Problem solved by replacing out.setChecklist( null ); with out.getChecklist().clear();
Can it be done with @mapping annotation with nullValuePropertyMappingStrategy = CLEAR?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions