When @Embedded
is used, and it has @EmbeddedParameters(nullAllowed = true)
, no data will be saved for its (embedded) fields even if all the fields are entered in a view.
An example project:
component-with-embeddable.zip (1.0 MB)
How to reproduce:
a) Working example:
- Open http://localhost:8080/test-entities
- Click the “Create” button and enter 1 in all 4 fields.
- Click the “OK” button.
- A new line with 4 1s in all the columns is added.
b) Non-working example:
- Stop the application.
- Open
com/company/componentwithembeddable/entity/TestEntity.java
and change the only@EmbeddedParameters(nullAllowed = false)
to@EmbeddedParameters(nullAllowed = true)
<= changed totrue
- Open
com/company/componentwithembeddable/entity/CodedText.java
and change the only@EmbeddedParameters(nullAllowed = false)
to@EmbeddedParameters(nullAllowed = true)
<= changed totrue
- Run the application.
- Open http://localhost:8080/test-entities
- Click the “Create” button and enter 2 in all 4 fields.
- Click the “OK” button.
- A new line with 2 in the first column is added, but the other 3 columns are empty (the data was not saved for them).
A similar behavoir was reported in Entity inspector errors with embedded entity, but it relates to creating records using Entity Inspector. Dmitriy recommended: “Therefore, to edit this type of entity, you need to create your own views.” This is what I created in the attached project and it still doesn’t save the embedded fields. It lets you enter the values, but it doesn’t add them to the view’s DataContext
.
The view can check that the nullable embedded property has values for some of its fields and it is not null
. If I understand Dmitriy, the nullable embedded property (entity) is not created when the view is opened which is probably causing the problems. The embedded entity should be created and placed in the view’s DataContext
. If upon saving the view’s DataContext
, all the fields for the embedded entity are null
, then the embedded entity should be set to null
in the DataContext
. Otherwise the values should be saved.
Can we please treat this as a bug
Jmix version: 2.5.1
Jmix Studio Plugin Version: 2.5.1-243
IntelliJ version: IntelliJ IDEA 2024.3.5 (Community Edition)