BeforeInsertEntityListener vs EntityChangedEvent Listener

Hello,
after quite a while I restart working with cuba.

I am working on an external datastore with given data-structures and have i.e. to set edit-by and edit-Timestamp of the existing structure, and I can not use the existing cuba-columns.

I used to handle changes to an entity like for instance setting special timestamp values just before committing by using the BeforeInsertEntityListener and the BeforeUpdateEntityListener - interfaces.

Using these interfaces and the onBeforeInsert( entity, entityManager) /
onBeforeUpdate(entity, entityManager) methods made it easy to manipulate the entity before writing to the database, because the entity is given as a parameter.

Now there is the new EntityChangedEventListener where in the beforePersist() method i get the entity which I can manipulate, but in the beforeCommit() I just get the id of the entity, and not the entity itself, so that I have to read the entity. And I only found an example how to manipulate i.e. child or parent objects and save them, rather than manipulating the entity itself.

I know that the old listeners are still usable when implementing “by hand”, but I wonder if there is a drawback when using the old methods in any kind. Or do I missing some in handling the entity when using the new EntityChangedEventListener?

What would be the right/best way to do this?

Thanks
Manfred

Hi,
Old entity listeners are considered to be too complex for newbies because of some problems (early persistence context flushes, dealing with unfetched attributes), so we hid them in favour of EntityChangeEvent.

This is intended. You need to read the entity.

It is advised to use new documented API. Entity listeners are kind of internal now, and their API may change in the future versions of the framework or may be dropped at all.

Hi,
thanks for the clarification!
Hope I can figure out how to redesign the old code in an easy way.

Regards
Manfred