Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to trigger pre-update computation on parent? (When a payment is updated, what is the cleanest way to trigger invoice pre-update computation? )
How to trigger pre-update computation on parent? [message #869324] Thu, 03 May 2012 04:26 Go to next message
Christophe Bismuth is currently offline Christophe Bismuth
Messages: 67
Registered: July 2009
Location: Paris, France
Member

Hi,

Here is the simplified legacy data model: a one-to-many relationship between Invoice and Payment (an invoice can have many payments). Besides, the Invoice entity has a persistent field containing the sum of all associated payments.
This sum is computed in a preWrite API called from @PreCreate and @PreUpdate hooks of the Invoice entity.

The question is: what is the cleanest way to trigger the invoice sum computation when one of its payments created or updated?

I've set a CascadeType.MERGE on both sides of this bidirectional association. But to get the @PreUpdate API called on the Invoice entity I have to manually trigger to sum of its payments.
I wish the only update of a payment automatically triggered the update of its associated invoice.

Thanks,
Chris
Re: How to trigger pre-update computation on parent? [message #869528 is a reply to message #869324] Thu, 03 May 2012 10:39 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

It may be best to handle this in your object model. When a Payment is added to your Invoice update its sum in its addPayment() method.

James : Wiki : Book : Blog : Twitter
Re: How to trigger pre-update computation on parent? [message #869746 is a reply to message #869528] Fri, 04 May 2012 03:56 Go to previous message
Christophe Bismuth is currently offline Christophe Bismuth
Messages: 67
Registered: July 2009
Location: Paris, France
Member

Thank you James.
I totally agree with you, but the domain model contains a bunch of legacy business code gathered in a single API of each entity.
Unfortunately without enough unit tests it would be too risky to split it in the target API.
Previous Topic:unexplained insert
Next Topic:Exceptions between MySQL and Eclipse using the clause SELECT in a table named condition
Goto Forum:
  


Current Time: Thu Jul 24 16:02:10 EDT 2014

Powered by FUDForum. Page generated in 0.01664 seconds