开发者

JPA PreUpdate implemented using DescriptorEventAdapter called after find/select

I have implemented a DescriptorE开发者_如何学CventAdapter for JPA (eclipselink). It performs simple timestamp operations. The preUpdate method is being called, however it is being called too often. It gets called and updates the timestamp, even on find/select operations.

The issue I'm running into appears to occur in a different JPA framework also, http://markmail.org/message/nank44rgp4xi2ita#query:JPA%20preupdate%20being%20called%20after%20find+page:1+mid:xssqpg7hm4mesfl5+state:results.

I have attempted to:

  • check the ChangeSet on the DescriptorEvent, this is always null
  • check the code on the DescriptorEvent, this is always 6

I have not been able to find any other flag or attribute that says "this object really was updated".

How do I get preUpdate to act only when a record really was updated and not merely selected?


http://wiki.eclipse.org/Configuring_a_Descriptor_(ELUG)#Table_115-27

The preUpdate is called all the time, apparently. aboutToUpdate is the better method to call to trigger when an update needs to be done.


Here's the solution i came up with after reading this question; I also found that the ChangeSet on the DescriptorEvent always seems to be null.

I did however notice that the event has methods to get the before and after objects:

 Object oldObject = event.getOriginalObject();
 Object newObject = event.getSource();

which would allows you to do manual comparison of the fields. Using reflection you can write a bit of code that could compare all the fields in any class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜