I'm creating an object Employee
, and I also want to create another object Event
which acts as a log of the creation of the employee. However, the way I'm doing it does not persist the Event.
@Transactional
public Mono<Employee> createEmployee(String name) {
return Mono.fromCallable(() -> {
Employee employee = new Employee();
employee.setName(name);
return employee;
})
.flatMap(employee -> {
return employeeRepository.save(employee);
})
.doOnNext(employee -> {
Event event = new Event();
event.setDetail("Created employee : " + employee.getName());
eventRepository
.save(event)
// .subscribe() // that didn't help
;
});
}
Repositories :
@Repository
public interface EmployeeRepository extends ReactiveCrudRepository<Employee, UUID> {
}
@Repository
public interface EventRepository extends ReactiveCrudRepository<Event, UUID> {
}
The employee will be saved, but not the event. I'm not really sure how this should be coded.