JPA Display Error - Comment Fetching

I am trying to get comments using the ticket field as a foreign key, but I get the following errors:

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]

This is the code I use in my javabean: - Hide quoted text -

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

thank

+5
source share
1 answer

Object A Ticket, obviously, cannot be equal to 751. Its identifier can. So,WHERE c.ticket.id = 751

(In the future: I doubt that you will hardcode the ID, so use a named parameter)

+10
source

All Articles