I'm using Quarkus Reactive and I'm trying to insert data to DB if duplicate record is not found on DB, here's my line of code
@ApplicationScoped
public class MovieRepositories implements IMovieRepositories {
@Inject
MovieMapper mapper;
@Override
public Uni<Object> create(MovieEntity entity) {
final var data = mapper.toEntity(entity);
final var dataMovie = MovieEntity
.find("name=?1 and deleted_at is null", entity.getName());
return dataMovie.firstResult().onItem().ifNotNull()
.failWith(new ValidationException("Movie already exist"))
.call(c -> MovieEntity.persist(data))
.chain(d -> Uni.createFrom().item(data.getId()));
}
however, this code terminates after failure on this line of code
.failWith(new ValidationException("Movie already exist"))
and persist is never executed.
How to make this code insert data if no duplicate record is found on?
Thanks in advance