Reputation: 2797
EclipseLink provides the @ReadOnly annotation to specify an entity is 'read-only'. The EclipseLink documentation says that
You should not modify read-only entities. Doing so can corrupt the EclipseLink cache. To modify a read-only entity, it must cloned or serialized.
But what is about creating and persisting a new instance when the application is running? I can understand that one should not modify an instance because the same instance may be shared with several clients, so we do not have the usual level of isolation (is this the case?) but I do not see a reason why not to create new instances. Unfortunately I was not able to find something about this question in the documentation. Could you please clarify this?
Nearly the same question is about if one is allowed to delete and remove an instance from the persistence context if the application is running?
Upvotes: 0
Views: 247
Reputation: 21145
Read-only is a performance feature that tells EclipseLink it can avoid extra caching and change tracking on these entities since they are not intended for updates. As you've implied, this allows EclipseLink to give you the entity version from the shared cache rather then build managed instances from it, so it is not safe to make modifications to it, hence the warning. There should be no problem inserting read-only instances, though with delete, it might cause application problems if you find an entity in through an EntityManager but get an exception stating it doesn't exist later on in that same EntityManager/transaction.
Upvotes: 1