I am following a course on Spring Boot and creating a simple application that implements RestAPI. The application makes use of JPA, H2 Database and Spring Web. All libs are resolved, using Maven for building the application.
Created a Product entity with annotations:
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
The Product repository interface extends JPA
public interface ProductRepository extends JpaRepository<Product, String> {}
Using the method I am returning the product by id in such way:
@RequestMapping(path = "{id}", method = RequestMethod.GET)
public Product getProduct(@PathVariable(name = "id")String id){
return productRepository.findOne(id);
}
The problem that it can’t get compiled is because I am having such an error
Error creating bean with name 'productRepository' defined in com.example.restapi.repository.ProductRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Not a managed type: class model.Product
Also, the method I’m using to get the id from the client – it is passing a parameter as a java.lang.String to findOne method signature with string. e.g.
java: method findOne in interface org.springframework.data.repository.query.QueryByExampleExecutor<T> cannot be applied to given types;
required: org.springframework.data.domain.Example<S>
found: java.lang.String
reason: cannot infer type-variable(s) S
(argument mismatch; java.lang.String cannot be converted to org.springframework.data.domain.Example<S>)
Could you please guide me how to fix the error!?
Thanks.