До Spring Boot 2.2.5 @EntityGraph использовался для загрузки EAGER, но после 2.2.5 мне нужно добавить EAGER в attributePaths, например attributePaths = {"image", "role"}
How @EntityGraph работает или я делаю что-то не так. Проблема возникла, когда я перешел на более новую версию 2.2.4 -> 2.2.5
@Entity
@Getter
@Setter
public class Employee {
@Column
private String email;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "employees_roles",
joinColumns = @JoinColumn(name = "employees_id", nullable = false, referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "roles_id", nullable = false, referencedColumnName = "id")
)
private Set<Role> roles;
@JoinColumn(name = "image_id")
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private Image image;
}
@Repository
interface EmployeeRepository extends JpaRepository<Employee, Long> {
@EntityGraph(attributePaths = "image")
Optional<Employee> findByEmailIgnoreCase(String email);
}
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/employee", produces = MediaType.APPLICATION_JSON_VALUE)
public class EmployeeController {
private final EmployeeService employeeService;
@GetMapping(value = "/login")
public ResponseEntity<String> login(Principal user) throws IOException {
Employee employee = employeeService.findByEmailIgnoreCase(user.getName())
.orElseThrow(() -> new UsernameNotFoundException(USER_NOT_FOUND));
return ResponseEntity.ok(employee);
}
}