'Spring JPA Parameter value [1000] did not match expected type [ma.mycom.myapp.domain.Client (n/a)]
I have two entities called Appointement and Client, and I would like to get all the
appointements of a given client. I am struggling with the following error message when I try to do so.
2022-05-24 13:30:41.685 WARN 23252 --- [ XNIO-3 task-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [1000] did not match expected type [ma.mycom.myapp.domain.Client (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [1000] did not match expected type [ma.mycom.myapp.domain.Client (n/a)]]
Here are my entities:
Client.java
@Entity
@Table(name = "CLIENTS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Client implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
//other attributes, getters, setters
}
Appointment.java
@Entity
@Table(name = "APPOINTMRNTS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Appointment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
//other attributes
@ManyToOne
@JoinColumn(name = "ID_CLIENT")
private Client client;
//getters, setters
}
Controller, and how I call the query:
List<Appointement> clientAppointements = appointementRepository.findAllByClient(idClient);
Here is the query used in AppointementRepository.java (I guess it's the source of the problem)
@Query(
name = "SELECT pe.* FROM APPOINTEMENTS pe INNER JOIN CLIENTS e ON pe.ID_CLIENT = e.ID WHERE e.id = ?1",
nativeQuery = true
)
List<Appointement> findAllByClient(Long idClient);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
