I'm porting a legacy application which impemented a fairly simple header/detail parent child relationship. I'm also using the DAO architecture as suggested in the "In Action" book. The parent object contained a persistent running total of the quantity and amount totals of all the children. In the old application, the setQuantity() and setAmount() of the child called an update() method in the parent to update the totals on the fly.
I'm unsure how to do this in Hibernate. Since the setters are called often by reflection in object initialization, it's less clear to me how to keep the totals updated. I realize I can implement an interceptor that will update the totals when the object is saved, but in looking at the sample interceptor code, it doesn't look like it's meant to update objects other then itself in the interceptor. I also have the case of business rules which may or may not allow upates to the child object based on different attribute settings (e.g. an order that has been processed may not have its quantity changed. How are these types of business rules typically implemented in Hibernate. I know they must be pretty common mechanisms.
I'm using Hibernate 2.1.7, JDK 1.4.2 with Oracle 9.2.0.5
|