Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
704 stars 83 forks source link

Entity View Module: Partial update does not respect empty collections #1521

Open ahofmeister opened 1 year ago

ahofmeister commented 1 year ago

Description

For partial updates eg via PATCH request it is not possible to set properties to null or empty for collections.

Expected behavior

We expect that properties can be set to null or empty in case of collections.

Actual behavior

No update statement is executed and therefore the property does not change in any way

Steps to reproduce

https://github.com/ahofmeister/bp-collection-empty-reproducer - there is a test case to reproduce the issue. Note the reproducer is only for collections

Environment

Version: 1.6.1
JPA-Provider:
DBMS:
Application Server: Quarkus 2.7.5.Final

beikov commented 1 year ago

Thanks for the report. In the meantime, you can use saveFull as a workaround to also flush the collection. If that doesn't work because you want to apply only partial state, you will have to load the updatable entity view first and the apply the JSON onto that object via the EntityViewAwareObjectMapper. I'll try to see if I can fix that soon though, as I think this might be easy!

ahofmeister commented 1 year ago

FYI The workaround works well :) But could lead to a complete change of workflows. For example: We use PATCH to update our entities via API and the clients are used to only send the relevant data. Forcing the clients to update their code to send the whole entity (state) to the API is something we want to avoid if possible

dsarlo-viso commented 1 year ago

Wanted to add here that this is something we ran into last week as well. We had no idea this was the case by default. Hoping this will make it into 1.6.9!