When saving an entity through a custom service, dynamic attributes aren’t loaded on the entity from inside it’s listener even if I’ve loaded the dynamic attributes on the entity before calling merge. To have access to dynamic attributes it appears that I’ll need to load it myself. I’ve used DynamicAttributesManagerAPI and successfully loaded my dynamic attributes in the listener, but after using it there are strange side affects such as persistenceTools.isDirty no longer return my dirty fields, the EntityManagerContext.attributes have changed. Is fetchDynamicAttributes doing a save on my record already? am I going about this the right way to get dynamic attributes on my entity in the listener when there is none loaded? Thanks.
you’re right. The only way to get dynamic attributes in the entity listener that was fired after you called EntityManager.merge() is to use the DynamicAttributesManagerAPI. The reason why PersistenceTools tells you that there are no dirty fields is that DynamicAttributesManagerAPI.fetchDynamicAttributes executes JPQL query. When the query is executed, all changes from the persistence context is flushed to the database. So, if you need to get a list of dirtyFields, do it before you load dynamic attributes.