In an EntityListener I cannot load an extended view for the entity to monitor a related entity

Hi,

when I store an entity A in the databes, I need to record some manual sql statements in a parallel table (not cuba table, complete different one)… so what I do is, via an A entity listener, call to the method in charge of traversing the A entity and storing the data manually…

I have however an entity B which is related to A in a O-t-M fashion. Surprisingly if I debug the A entity instance in the onAfterInsert() method in the A entitylistener, the A entity comes in without it’s B related records being populated… although the records/instances of B are there when storing the A instance. So apparently, the A instance coming in the entitylistener comes without O-t-M related entities.

I have tried reloading through Persistence/DataManager, but no luck, the entity is not there, nor I have access to the entity, hence not being able to be compliant with the data I need to write in my additional table.

I presume the original recording transaction is not over and therefore the instance is not in the DB to be reloaded. Then I need a way to call the method once the Transaction if fully completed. Or are there any other solutions? I can attach manually

Any help is greatly appreciated.

Regards,

Carlos.

Hi,

Have you considered transaction listeners?

Thanks will give it a try and post back results.

Regards,
Carlos Conti.

I would argue that EntityChangedEvent with TransactionPhase.AFTER_COMMIT is more suitable for the task. Just reload the entity with the desired view and traverse the graph.