gpt4 book ai didi

mysql - 属性访问异常 : Error accessing field

转载 作者:行者123 更新时间:2023-12-01 13:39:20 34 4
gpt4 key购买 nike

我有一个实体 用户 :

@Entity
public class User implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Long id;

public Long getId() {
return id;
}
...}

我正在尝试从数据库的任务中删除用户:
@Modifying
@Query("DELETE FROM Collaborator c WHERE c.user = :userId AND c.task = :taskId")
void deleteUserFromTask(@Param("userId") Long userId, @Param("taskId") Long taskId);

这是用户和协作者(我要从中删除的表)之间的关系:
用户
@JsonIgnore
@OneToMany(mappedBy="user", fetch = FetchType.EAGER)
private Set<Collaborator> collaborators = new HashSet<>();

合作者
    @ManyToOne(cascade = {CascadeType.MERGE,
CascadeType.DETACH,
CascadeType.REFRESH },
fetch = FetchType.EAGER)
@JoinColumn(name = "UserID", nullable = true)
private User user;

但我收到此错误:
Caused by: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Long gestionprojet.java.entities.beans.User.id] by reflection for persistent property [gestionprojet.java.entities.beans.User#id] : 1

Hibernate Version : 5.2.6.FINAL

最佳答案

您的参数不匹配,即您尝试指定 Long 作为用户类型的参数:

您可以通过以下两种方式之一更改它:

@Query("DELETE FROM Collaborator c WHERE c.user.id = :userId AND c.task.id = :taskId")
void deleteUserFromTask(@Param("userId") Long userId, @Param("taskId") Long taskId);

或者
@Query("DELETE FROM Collaborator c WHERE c.user = :user AND c.task = :task")
void deleteUserFromTask(@Param("user") User user, @Param("task") Task task);

关于mysql - 属性访问异常 : Error accessing field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41642939/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com