I use spring boot 3
I created a query to get a part of entity via a projection
public interface UserConnexion {
Long userId();
String name();
CatogoryUserCode user();
interface CatogoryUserCode{
String code();
}
}
@Query("""
select u.userId, u.name, ce.code from User u
join u.categoryUserCode ce
WHERE u.userId=:userId
""")
public Optional<UserConnexion> findByIdUserProjection(Long userId);
Query is generated
So i created an endpoint
@GetMapping("/user/{id}")
public ResponseEntity<UserConnexion> findLigtUserById(@PathVariable Long id) {
return new ResponseEntity<UserConnexion>(userManager.findLigtUserById(id), HttpStatus.OK);
Edit
Method in userManager
@Transactional(readOnly = true)
public UserConnexion findLigtUserById(Long id) {
return userRepository.findByIdUserProjection(id).orElseThrow(() -> new EntityNotFoundException(id + " "));
}
When endpoint is called
Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: No acceptable representation