spring data jpa:在结果元组中找不到别名!确保您的查询定义了别名 [英] spring data jpa: No aliases found in result tuple! Make sure your query defines aliases
问题描述
当我尝试使用存储库界面吸引用户时,收到以下异常 "org.springframework.dao.InvalidDataAccessApiUsageException:在结果元组中找不到别名!请确保您的查询定义了别名! java.lang.IllegalStateException:在结果元组中找不到别名!请确保您的查询定义了别名!"
When I try to get the users using repository interface I received following exception "org.springframework.dao.InvalidDataAccessApiUsageException: No aliases found in result tuple! Make sure your query defines aliases!; nested exception is java.lang.IllegalStateException: No aliases found in result tuple! Make sure your query defines aliases!"
存储库:
@Repository
public interface UserRelationshipRepository
extends JpaRepository<UserRelationship, Long>, QueryDslPredicateExecutor<UserRelationship> {
@Query(value = "SELECT ur.id.toUser FROM UserRelationship ur WHERE ur.fromUser = :fromUser AND ur.relationshipTypeId = 1")
Set<User> findUserFriends(@Param("fromUser") User fromUser);
}
实体:
@Entity
@NamedEntityGraph(name = "graph.User", attributeNodes = {})
@Table(name = "users")
public class User extends BaseEntity implements UserDetails {
private static final long serialVersionUID = 8884184875433252086L;
@Id
@SequenceGenerator(name = "users_id_seq", sequenceName = "users_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "users_id_seq")
private Long id;
@Column(name = "first_name")
private String firstName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fromUser", cascade = CascadeType.ALL)
private Set<UserRelationship> relationships = new HashSet<UserRelationship>();
// getters setters
}
@Entity
@NamedEntityGraph(name = "graph.UserRelationship", attributeNodes = {})
@Table(name = "users_relationships")
public class UserRelationship extends BaseEntity implements Serializable {
private static final long serialVersionUID = -6367981399229734837L;
@EmbeddedId
private final UserRelationshipId id = new UserRelationshipId();
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "from_user_id", nullable = false)
@MapsId("fromUserId") // maps fromUserId attribute of the embedded id
private User fromUser;
@Column(name = "relationship_type_id")
private Long relationshipTypeId;
}
我正在使用弹簧数据jpa的' 1.11.0.BUILD-SNAPSHOT '版本. 这已经是问题,并且被标记为已解决,但是我仍然可以解决
I am using '1.11.0.BUILD-SNAPSHOT' version of spring data jpa. This is already known issue, and it is marked as resolved, but I am still get it.
请帮我解决这个问题.
更新:
如果我将存储库方法的返回类型更改为Set<Object>
,则一切正常.
Update:
If I change repository method's return type to Set<Object>
then all works fine.
推荐答案
您正在遇到 DATAJPA -885 ,该问题已经修复,将成为Spring Data Hopper SR2版本的一部分.
You're running into DATAJPA-885, which is already fixed and will be part of the Spring Data Hopper SR2 release.
这篇关于spring data jpa:在结果元组中找不到别名!确保您的查询定义了别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!