Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] @PreUpdate question

Hi Laird,

  A couple of comments:

1. I agree, I don't think JPA handles this at the moment

2. If your classes are weaved for change tracking the changes are actually computed even earlier for some cases

3. EclipseLink has an event system that goes beyond JPA. Take a look at org.eclipse.persistence.descriptors.DescriptorEventAdapter. You should be able to create a subclass of that an add it to any descriptor in a DescriptorCustomizer. The postMerge method might be a good one to try.

-Tom

Laird Nelson wrote:
I don't think the JPA specification addresses this fully, so I thought I'd ask it here.

I have an entity that consists of an integer ID and a byte[] field mapped onto a @Lob column.

The data that goes into that byte array is computed from another operation.

I had the bright idea that I'd stick a @PreUpdate annotation on the operation that computes the data. Easy, I thought, this will ensure that the byte[] field is always up to date when the entity is updated.

I am observing (by turning EclipseLink logging up to FINEST) that this only fires when EclipseLink has determined that the state of the object has changed.

I had assumed that @PreUpdate fired sometime "before" an EntityManager#merge() operation started. That is, I had assumed that when you called EntiytManager#merge() and passed it an entity, that entity's @PreUpdate callbacks would fire, whether (ultimately) EclipseLink determined it needed to get flushed to the database or not. I realize now that I must be wrong--the @PreUpdate must only fire when (effectively) an UPDATE SQL statement is about to be fired.

My question is: is there any kind of interceptor or callback mechanism I can employ that fires before the EclipseLink I-wonder-if-this-object-needs-to-be-flushed-to-the-database-or-not process (change tracking) begins?

Thanks,
Laird


------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top