Originally posted by **underscore05** November 22, 2024
I have this code where I try to get an entity in a sequential manner. At the last flatMap, I can see that agent and customer is still assigned to newJobPosting. But persisting it causes an error like `ava.util.concurrent.CompletionException: org.hibernate.PersistentObjectException: detached entity passed to persist`. I suspect that the agent and customer is already detached at that point but I don't know what to do to attached them again. I am using reactive-panache and repository for agent, customer and jobposting entity.
```java
Log.info("Creating new job-posting");
return Uni.createFrom().item(() -> modelMapper.map(request, JobPosting.class))
.flatMap((newJobPosting) -> getAgentOrException(jwtId).map(agent -> {
newJobPosting.setAgent(agent);
return newJobPosting;
}))
.flatMap((newJobPosting) -> {
if(request.getAssignedCustomerId() != null && JobPostingVisibility.PRIVATE_POST.equals(request.getVisibility())) {
return getCustomerOrException(request.getAssignedCustomerId())
.map(customer -> {
newJobPosting.setCustomer(customer);
return newJobPosting;
});
}
return Uni.createFrom().item(newJobPosting);
})
.flatMap(newJobPosting -> {
if(newJobPosting.getAgent() != null) {
Log.infof("Has Agent! %s", newJobPosting.getAgent().getJwtId());
}
if(newJobPosting.getCustomer() != null) {
Log.infof("Has Customer! %s", newJobPosting.getCustomer().getJwtId());
}
return jobPostRepository.persist(newJobPosting);
});
```
Discussed in https://github.com/quarkusio/quarkus/discussions/44621