【发布时间】:2018-04-08 04:19:33
【问题描述】:
我在使用 Spring JPA 并尝试检索对象列表时遇到了这个问题。
这是我要检索的类
@Entity
@Table(name="OBJECTSTERMIC")
public class TermicObject {
@Id
@Column(name="TERMICID")
private long termicId;
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="OBJECTID",columnDefinition="INTEGER")
private Object object;
@Column(name="CONTECA_RIF")
private int contecaRif;
@Column(name="CONTECA_VAL")
private int contecaVal;
@Column(name="TYPE")
private String type;
//getters and setters
Object 类在 MySQL 上的主键存储为 Integer,这确实是 Object
@Entity
public class Object {
@Column(name="OBJECTID")
@Id
@JsonProperty("OBJECTID")
private int objectId;
....
所以,没有地方设置 Long...
现在,我只需调用一个服务类
@Override
public List<TermicObject> findAll() {
return repository.findAll();
}
得到了这个异常
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TypeMismatchException: Provided id of the wrong type for class it.besmart.db_eipo.persistence.model.Object. Expected: class java.lang.Integer, got class java.lang.Long; nested exception is java.lang.IllegalArgumentException: org.hibernate.TypeMismatchException: Provided id of the wrong type for class it.besmart.db_eipo.persistence.model.Object. Expected: class java.lang.Integer, got class java.lang.Long
Object Id应该是Long的设置在哪里?
【问题讨论】:
标签: mysql spring-data-jpa