I’m working on SpringBoot-based platform which uses EclipseLink as ORM.
In my main entity there is a attribute represents ManyToOne
association with another entity. Attribue has the following annotations:
@ManyToOne(fetch = FetchType.LAZY, optional = true, cascade = CascadeType.ALL)
@JoinColumn(name = "unit_id", referencedColumnName = "id", nullable = true)
protected Dict unit;
The problem occurs when I try to update existing main entity.
There’re two scenarios of updating:
- I set
null
value forunit
attribute - I replace old
unit
value with another one
In both scenarios I set some new values for other fields and it saved correctly.
After main entity saved by calling entity = repository.save(entity);
I call getUnit()
method for entity
object and for the first scenario it returns old value of unit
(this old value also stored in DB instead of null
) though I expect null
as returned value, but for the second scenario it returns new value of unit
, as expected, and in DB this new value stored too. Because of that it seems there is no problem with transaction.
There’re no exceptions during execution. In debug I see null
value for unit
attribute of entity
object until getUnit()
method is called. The corresponding field in DB table is nullable. HSQLDB used as DB during tests.
So what’s the problem? Why I can’t nullify unit
attribute and corresponding DB field?
Regards,
Lev