My current project uses HSQLDB2.0 and JPA2.0 .
The scenario is: I query DB to get list of contactDetails
of person
. I delete single contactInfo
at UI but do not save that data (Cancel the saving part).
I again do the same query, now the result list is 1 lesser than previous result coz I have deleted one contactInfo at UI. But that contactInfo
is still available at DB if I cross check.
But if I include entityManager.clear()
before start of the query, I get correct results every time.
I dont understand this behaviour. Could anyone make it clear for me?
The behaviour of
clear()
is explained in its javadoc:That is, removal of
contactInfo
is not persisted.ContactInfo
is not getting removed from the database because you remove the relationship betweenContactDetails
andContactInfo
, but notContactInfo
itself. If you want to remove it, you need either do it explicitly withremove()
or specifyorphanRemoval = true
on the relationship.Rather than querying again, try this:
A more complete example: