1

I am trying to trigger a method from one if my app services when an entity property is updated.

What i tried so far: I tried to create an AuditListener and use @PostUpdate, but with this approach i am having many problems with @Autowire my service + i cannot know which porperty has been updated, also i am lookin into envers implementation, placing @Audited only on the property, again having trouble with the service call.

I think Auditables are not for this kind of implementations, so i tried also with interceptors and event listeners, but again i'm strugglin with my service, an again i don't think this is the best approach since its interceps all events and even if i am filtering checking the entity i dont like to trigger it so much.

So, which other ways i have to do such kind of implementation, i am so new with java so probably theres and easy way to do this that i am missing.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
  • "placing @Audited only on the property" - "i cannot know which porperty has been updated", 1. sounds like you only want to log 1 property, 2. sounds like you want to log all properties, which of the 2 is it? Auditing the entity sounds exactly like what you want, can you elaborate which issues you are having? – PaulD Jun 07 '22 at 10:49
  • Ok, I may not have expressed myself well, placing @Audited only on the property was my second approach, to know excatly what property was being updated. What i am trying is notify an external app, that some certain relevant property of the entity has changed. – Arthur Reinhart Jun 07 '22 at 13:12
  • Btw, the error i am getting is: javax.persistence.RollBackException: Error while commiting the transaction – Arthur Reinhart Jun 07 '22 at 15:24
  • A RollBackException is usually the side effect of another Exception, the real culprit is probably right before that in your log. Maybe you can look into making an event class that you can subscribe to and then invoke during saving your entity if a certain property has been changed? the following is an example of an event like structure in java: https://stackoverflow.com/a/71135437/11764050 – PaulD Jun 08 '22 at 07:07

0 Answers0