Skip to main content


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 08:26 Go to next message
Christophe Bismuth is currently offline Christophe BismuthFriend
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 14:39 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
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 07:56 Go to previous message
Christophe Bismuth is currently offline Christophe BismuthFriend
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: Fri Apr 26 00:23:08 GMT 2024

Powered by FUDForum. Page generated in 0.02480 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top