JPA映射中的错误 - 获取注释

Ste*_*ffi 5 java jpa eclipselink

我正在尝试使用票证字段作为外键来获取注释,但我收到以下错误:

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]
Run Code Online (Sandbox Code Playgroud)

这是我在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();
    }
Run Code Online (Sandbox Code Playgroud)

谢谢

Boz*_*zho 10

一个Ticket对象显然不能等于751.它的ID可以.所以WHERE c.ticket.id = 751

(对于未来:我怀疑你将硬编码ID,所以使用命名参数)