我正在尝试使用故障单字段作为外键来获取评论,但我收到以下错误:
Caused by: Exception [EclipseLink-6078] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.QueryException
Exception Description: The class of the argument for the object comparison is incorrect.
Expression: [
Base com.test.forum.model.Comment]
Mapping: [org.eclipse.persistence.mappings.OneToOneMapping[ticket]]
Argument: [751]
这是我在javabean中使用的代码: - 隐藏引用的文字 -
@JoinColumn(name = "ticket", referencedColumnName = "id")
@ManyToOne(optional = false)
private Ticket ticket;
public List<Comment> findComment(int id) {
Query q = em.createQuery("SELECT c FROM Comment c WHERE c.ticket = 751");
return q.getResultList();
}
谢谢
答案 0 :(得分:10)
Ticket
对象显然不能等于751.它的ID可以。所以WHERE c.ticket.id = 751
(对于未来:我怀疑您将对ID进行硬编码,因此请使用命名参数)