I am attempting to persist additional entities in a @PostPersit
method from a domain class.
As the @PostPersist
method is on the domain class I do not have access to any of the service classes/entityManager - to get around this I am using the ApplicationService (singleton) which has the service classes autowired in:
@PostPersist
public void createNotification() {
Notification n = new Notification();
n.setActivity(this);
ApplicationService.getInstance().sendNotifications(n);
}
The ApplicationService method just invokes a method in the Autowired service class:
public void sendNotifications(Notification n) {
notificationService.distributeNotifications(n);
}
The service class is a standard spring annotated service class and has a transactional method that creates and persists new objects
@Transactional
public void distributeNotifications(Long accountId, Notification n) {
this.createNotification(n);
...
}
However, the additional entity is never being persisted - Can anyone advise where the above is going wrong? Am I mis-understanding the transactional boundaries in hibernate?
Thanks.