我收到错误
java.lang.IllegalArgumentException:参数值 [2] 与 org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryImpl.java:885) 的预期类型 [com.cityBike.app.model.User (n/a)] 不匹配) 在 org.hibernate.jpa.internal.QueryImpl$ParameterRegistrationImpl.bindValue(QueryImpl.java:248) 在 org.hibernate.jpa.spi 的 org.hibernate.jpa.internal.QueryImpl.access$000(QueryImpl.java:80) .BaseQueryImpl.setParameter(BaseQueryImpl.java:631) 在 org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:180) 在 org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:49) 在com.cityBike.app.service.RentService.getAllByUser(RentService.java:22)
下面是我的代码片段,我该如何解决这个问题?
文件出租.java
@Entity
@Table(name="Rent")
public class Rent implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@ManyToOne
@JoinColumn(name = "start_id")
private Station start_id;
@ManyToOne
@JoinColumn(name = "meta_id")
private Station meta_id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user_id;
...
文件用户.java
@Entity
@Table(name="Users")
public class User implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@Column(name = "login")
private String login;
...
文件 RentService.java
@Service
public class RentService {
@PersistenceContext
private EntityManager em;
@Transactional
public List<Rent> getAllByUser(int user_id){
System.out.println(user_id);
List<Rent> result = em.createQuery("from Rent a where a.user_id = :user_id", Rent.class).setParameter("user_id", user_id).getResultList();
System.out.println(result);
return result;
}
}
我应该在控制台上显示时添加“user_id”是正确的,因为它具有这样的数值 ex。2或3。请指导和帮助。