Java 在此ManagedType上找不到具有给定名称[trackers]的属性
我试图为Spring上的应用程序提供实体之间的延迟获取关系 模型“用户”: 继承了带有@EntityGraph的JPA存储库。通过这一点,我试图为select用户提供与以下相关的所有跟踪器:Java 在此ManagedType上找不到具有给定名称[trackers]的属性,java,spring,hibernate,lazy-initialization,Java,Spring,Hibernate,Lazy Initialization,我试图为Spring上的应用程序提供实体之间的延迟获取关系 模型“用户”: 继承了带有@EntityGraph的JPA存储库。通过这一点,我试图为select用户提供与以下相关的所有跟踪器: @Repository @Transactional(readOnly = true) public interface CrudUserRepository extends JpaRepository<User, Integer> { @EntityGraph (attributePa
@Repository
@Transactional(readOnly = true)
public interface CrudUserRepository extends JpaRepository<User, Integer> {
@EntityGraph (attributePaths = {"trackers"}, type = EntityGraph.EntityGraphType.LOAD)
@Query("SELECT u FROM User u WHERE u.id=?1")
User getByIdWithTrackers(int id);
}
和控制器:
@RestController ("userRestController")
@RequestMapping(value = UserRestController.USER_URL, produces =
MediaType.APPLICATION_JSON_VALUE)
public class UserRestController extends AbstractUserController {
public static final String USER_URL = "/customers";
@GetMapping("/{id}")
public User getByIdWithoutTrackers(@PathVariable int id) {
return super.getByIdWithoutTrackers(id);
}
@GetMapping("/{id}/withTrackers")
public User getByIdWithTrackers(@PathVariable int id) {
return super.getByIdWithTrackers(id);
}
}
查询“/customers/1”可以正常工作。它返回没有跟踪器的所有客户(相应地,延迟获取)
但是“/customers/1/withTrackers”返回以下异常:
lang.IllegalArgumentException: Unable to locate Attribute with the the given name [trackers] on this ManagedType [ru.spb.model.User]"}
哦,这是个愚蠢的错误。在用户界面中,我写“追踪者”。但在CrudUserRepository的AttributePath“追踪者”中
@Repository
public class AnketUserRepository implements UserRepository {
@Autowired
private CrudUserRepository crudRepository;
@Override
public User getByIdWithoutTrackers(int id) {
return crudRepository.findById(id).orElse(null);
}
@Override
public User getByIdWithTrackers(int id){
return crudRepository.getByIdWithTrackers(id);
}
}
@RestController ("userRestController")
@RequestMapping(value = UserRestController.USER_URL, produces =
MediaType.APPLICATION_JSON_VALUE)
public class UserRestController extends AbstractUserController {
public static final String USER_URL = "/customers";
@GetMapping("/{id}")
public User getByIdWithoutTrackers(@PathVariable int id) {
return super.getByIdWithoutTrackers(id);
}
@GetMapping("/{id}/withTrackers")
public User getByIdWithTrackers(@PathVariable int id) {
return super.getByIdWithTrackers(id);
}
}
lang.IllegalArgumentException: Unable to locate Attribute with the the given name [trackers] on this ManagedType [ru.spb.model.User]"}