我正在尝试使用Spring Boot(显然我是新手)以及Hibernate。
@Entity
public class UserRole {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long userRoleId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="user_id")
private User user;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="role_id")
private Role role;
}
我试图只检索用户对象列表而不必依赖UserRole对象List来获取它们。
我在UserRoleRepository中尝试了以下内容
@Query("select u.user from user_role u where u.role = :role")
public ArrayList<User> findByRoleQ(Role role);
当我尝试上述查询时,我得到了一个错配映射错误当我尝试按如下方式运行时
2018-01-27 18:14:12.299 WARN 10720 --- [主要] ationConfigEmbeddedWebApplicationContext:遇到异常 在上下文初始化期间 - 取消刷新尝试: org.springframework.beans.factory.UnsatisfiedDependencyException: 使用名称&#39; afdempUisuxAdminApplication&#39;创建bean时出错: 通过字段“userRoleService”表达的不满意的依赖性; 嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException: 使用名称&#39; userRoleServiceImpl创建bean时出错&#39;:不满意 通过字段“userRoleRepository”表达的依赖关系;嵌套 异常是org.springframework.beans.factory.BeanCreationException: 使用name&#39; userRoleRepository&#39;:init的调用创建bean时出错 方法失败;嵌套异常是java.lang.IllegalArgumentException: 查询方法公共摘要的验证失败 的java.util.ArrayList org.afdemp.uisux.repository.UserRoleRepository.findByRoleQ(org.afdemp.uisux.domain.security.Role)!
我做错了什么,有没有办法让它只返回用户列(因此用户列表)?