我看到了有关此主题的一些问题,但我的案例没有得到任何有效的解决方案
我的杰森序列化有一个例外,我有以下类
当我执行 GET Pacientes 时,我遇到了序列化权限类型的异常
2017-11-14 08:54:35.039 INFO 8724 --- [nio-8080-exec-1] o.h.e.internal.DefaultLoadEventListener : HHH000327: Error performing load command : org.hibernate.type.SerializationException: could not deserialize
2017-11-14 08:54:35.047 ERROR 8724 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize] with root cause
java.io.EOFException: null
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source) ~[na:1.8.0_144]
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source) ~[na:1.8.0_144]
at java.io.ObjectInputStream.readStreamHeader(Unknown Source) ~[na:1.8.0_144]
at java.io.ObjectInputStream.<init>(Unknown Source) ~[na:1.8.0_144]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:309) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:299) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
我正在使用框架 Spring boot 和 spring data jpa
Paciente 班
import java.io.Serializable;
import java.math.BigInteger;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import digifred.model.global.Entidades;
import digifred.model.global.IdentidadesGenero;
import digifred.model.global.OrientacoesSexuais;
import digifred.model.global.Pessoas;
@Entity
@Table(name = "pacientes", schema = "sau")
public class Pacientes implements Serializable {
private static final long serialVersionUID = 5776384003601026304L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idPaciente")
private Long idPaciente;
@JoinColumn(name="id_entidade")
@ManyToOne(cascade = CascadeType.ALL)
private Entidades entidade;
@Basic(optional = false)
@JoinColumn(name="idPessoa")
@ManyToOne(cascade = CascadeType.ALL)
private Pessoas pessoa;
@Column(name = "idResponsavel_familiar")
private BigInteger responsavelFamiliar;
@Column(name = "nomeResponsavel")
private String nomeResponsavel;
@Column(name = "cpfResponsavel")
private String cpfResponsavel;
@Column(name = "cnsResponsavel")
private String cnsResponsavel;
@Column(name = "flagAlergico")
private Integer flagAlergico;
@Column(name = "observacoesAlergias")
private String observacoesAlergias;
@Column(name = "microarea")
private String microarea;
@Column(name = "idDomicilio")
private Long idDomicilio;
@JoinColumn(name="idOrientacaoSexual")
@ManyToOne
private OrientacoesSexuais orientacaoSexual;
@JoinColumn(name="idIdentidadeGenero", insertable=false, updatable=false)
@ManyToOne
private IdentidadesGenero identidadeGenero;
@Basic(optional = false)
@Column(name = "flag_ativo")
private int flagAtivo;
@JoinColumn(name="idArea")
@ManyToOne
private Areas area;
@JoinColumn(name="idFamilia")
@ManyToOne
private Familias familia;
public Pacientes() {
}
getters and setters
}
看起来您正在尝试反序列化空流。
您不能简单地通过 REST 接口传输数据库实体,您必须创建 DTO 并传输它们而不是您的实体。
对我来说,原因是在关联上使用
@Column
而不是 @JoinColumn
。能够通过打开正在运行的查询的日志记录来找出答案:
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.springframework.transaction=DEBUG
logging.level.org.hibernate=DEBUG
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
tbh,不确定实际上需要哪些属性,但我在其他一些问题上找到了它们,并在调试时将它们全部打开。在日志中,我看到所获取的每一列都有一行,并且在我收到异常之前记录的最后一个是我有错误注释的关联的列值。
对我来说,相关错误“无效的流头:C3020D1B”是由于数字数据类型引起的,通过更改为长数据类型XD解决了,投入了几个小时!!!
对我来说,这个问题是由于声明类型为
Number
的字段引起的(将其更改为 Double
修复了错误)。