我正在尝试使用票证字段作为外键来获取评论,但出现以下错误:

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();
    }

谢谢

最佳答案

Ticket对象显然不能等于751。其ID可以。所以WHERE c.ticket.id = 751
(为了将来:我怀疑您将对ID进行硬编码,因此请使用命名参数)

09-10 07:45
查看更多