gpt4 book ai didi

java - 出现错误 org.hibernate.QueryException : illegal attempt to dereference collection

转载 作者:行者123 更新时间:2023-12-01 18:11:55 24 4
gpt4 key购买 nike

我有一个有很多员工的复习类。

Review.java 中的关联是

    @ManyToMany(targetEntity = Employee.class, cascade = { CascadeType.ALL })
@JoinTable(name = "review_employee",
joinColumns = { @JoinColumn(name = "reviewid") },
inverseJoinColumns = { @JoinColumn(name = "empid") })
private Set<Employee> employees;

当我尝试通过审核访问员工时,出现以下错误

   org.hibernate.QueryException: illegal attempt to dereference collection [review0_.id.employees] with element property reference [id] [FROM com.abc.model.Review r  LEFT JOIN fetch r.employees WHERE r.id = 1 AND ( r.employees.id = 11 )]
org.hibernate.QueryException.generateQueryException(QueryException.java:137)

感谢您的帮助。

<小时/>

更新

Employee.java

public class Employee  {
/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "empfirstname", nullable = false)
private String empFirstName;

@Column(name = "emplastname", nullable = false)
private String empLastName;

@Column(name = "empdesignation", nullable = false)
private String empDesignation;

@OneToOne
@JoinColumn(name = "employeetypeid", nullable = true)
private EmployeeType employeeType;

@Column(name = "employeeImageFileName", nullable = false)
private String employeeImageFileName;

private Boolean deleted;

...Getters & Setters...
}
<小时/>

Review.java

public class Review {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToMany(targetEntity = Employee.class, cascade = { CascadeType.ALL })
@JoinTable(name = "review_employee",
joinColumns = { @JoinColumn(name = "reviewid") },
inverseJoinColumns = { @JoinColumn(name = "empid") })
private Set<Employee> employees;

@Column(name = "customerfirstname", nullable = false)
private String customerFirstName;

@Column(name = "customerlastname", nullable = false)
private String customerLastName;

@OneToOne
@JoinColumn(name = "starratingid", nullable = false)
private StarRating starRating;

@Column(name = "reviewtitle", nullable = false)
private String reviewTitle;

@Column(name = "review", nullable = false)
@Type(type="text")
private String review;

...Getters & Setters...
}

最佳答案

您可以尝试从已加入的员工而不是评论的员工中引用该员工吗?试试这个:

FROM com.abc.model.Review r LEFT JOIN fetch r.employees reviewEmp WHERE r.id = 1 AND reviewEmp.id = 11

关于java - 出现错误 org.hibernate.QueryException : illegal attempt to dereference collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32344435/

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