In the application that we develop we have a hierarchy of objects:
CampaignStatus <- Campaign -> CampaignItem*
In plain words I have a Campaign
that has multiple CampaignItem
's, each Campaign
has a CampaignStatus
that is computed based on the number of items a given campaign has, or on different parameters.
Long story short, I need to update the campaign status of a given campaign, after the item related changes are saved in the DB.
In my opinion this sounds like the appropriate ground to work with aspects/ interceptors but I don't whether this is a good practice.
Q: so is it?
Q: can I trigger the interceptor after the transaction is committed?
No. This is a business requirement that should be implemented in your business layer. Just make sure that all updates of a campaign is made by a given service, and make this service also update the status accordingly.
You really want your database to be in a coherent state. So the campaign and its status must be updated in the same transaction. Otherwise, you might suceed to update the campaign and then fail to update the status, which would leave the database in an incoherent state. That's what transactions are all about.