总是在我尝试从JPA存储库中获取实体列表时,出现了这样的异常
org.springframework.orm.jpa.JpaSystemException: No default constructor for entity: : pl.hycom.hyper.hyebok.model.ServiceEntity$Id; nested exception is org.hibernate.InstantiationException: No default constructor for entity: : pl.hycom.hyper.hyebok.model.ServiceEntity$Id
我的实体中缺少什么。我在Embeddable类和外部类中都具有非参数构造函数和全参数构造函数。我找不到此问题的解决方案。
我在下面的实体
@Entity
@Table(name = "he_service")
public class ServiceEntity implements Serializable {
@EmbeddedId
private Id id ;
private String name;
public ServiceEntity() {
}
public ServiceEntity(Id id, String name) {
this.id = id;
this.name = name;
}
@Embeddable
class Id implements Serializable {
public Id() {
}
public Id(String serviceId, String clientId) {
this.serviceId = serviceId;
this.clientId = clientId;
}
@Column(name = "serviceId")
private String serviceId;
@Column(name = "clientId")
private String clientId;
public String getServiceId() {
return serviceId;
}
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
}
那里的存储库方法
@Query(value= "SELECT s FROM ServiceEntity s " +
"WHERE s.id.clientId = :clientId")
List<ServiceEntity> findByClientId(@Param("clientId") String clientId);
您的内部Id
类是非静态的,这意味着它将创建一个构造函数
class Id implements Serializable {
public Id(ServiceEntity arg0) {
}
// …
}
将其更改为static
课程
static class Id implements Serializable {
// …
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句