SO Link: https://stackoverflow.com/questions/52124727/error-in-saving-entity-by-extending-reactive-repository-in-springboot-with-webfl

Spring Boot Version:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Document POJO

@Document(collection = "users")
public class Employee implements Serializable {

    @Id
    private UUID id;

    private String firstName;

    private String lastName;

    private String email;


    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;

        Employee employee = (Employee) o;

        if (!getId().equals(employee.getId())) return false;
        if (getFirstName() != null ? !getFirstName().equals(employee.getFirstName()) : employee.getFirstName() != null)
            return false;
        if (getLastName() != null ? !getLastName().equals(employee.getLastName()) : employee.getLastName() != null)
            return false;
        return getEmail().equals(employee.getEmail());
    }

    @Override
    public int hashCode() {
        int result = getId().hashCode();
        result = 31 * result + (getFirstName() != null ? getFirstName().hashCode() : 0);
        result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0);
        result = 31 * result + getEmail().hashCode();
        return result;
    }
}

Reactive Repository

@Repository
public interface EmployeeRepository extends ReactiveMongoRepository<Employee, UUID> {

}

and here is my handler:

@Component
public class EmployeeHandler {

    @Autowired
    private EmployeeRepository employeeRepository;


    public Mono<ServerResponse> createNewEmployee(ServerRequest request) {
        Mono<Employee> employeeMono = request.bodyToMono(Employee.class);
        Mono<Employee> newEmployee = employeeRepository.save(employeeMono);
        return ServerResponse.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .build(newEmployee);
    }
}

Compile error "Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'com.kj.webfluxcruddemo.entity.Employee'" I am seeing in my handler at line: `Mono newEmployee = employeeRepository.save(employeeMono);

Same question is posted at stackoverflow two days back but didn't get any answer so kindly advise is it bug or am I missing something as followed all latest spring boot reference documents for reactive repository but all suggest same implementation which I did.

Comment From: snicoll

There is no need to open a duplicate here because you didn't get an answer in StackOverflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Please edit your description so that there is at least a reference to your SO post.

Comment From: kjoshi07

@snicoll not sure but it seems bug or not mentioned in spring doc if I missed something so let me know what should i do as next step.

here is link of SO: https://stackoverflow.com/questions/52124727/error-in-saving-entity-by-extending-reactive-repository-in-springboot-with-webfl

Comment From: hubSteve

I got the same problem but couldn't find any ways to solve it

Comment From: beszedics

You have to use modelMapper to map DTO to entity, after the mapping you can save.

https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application