【问题标题】:Error in JPA mapping - Fetch CommentsJPA 映射中的错误 - 获取评论
【发布时间】:2010-12-07 15:24:23
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: java jpa eclipselink


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多