[英]could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize
I have spend way too much find finding the root cause of the below error:我花了太多时间寻找以下错误的根本原因:
org.springframework.orm.jpa.JpaSystemException: could not serialize; org.springframework.orm.jpa.JpaSystemException:无法序列化; nested exception is org.hibernate.type.SerializationException: could not serialize嵌套异常是 org.hibernate.type.SerializationException: 无法序列化
I am trying to save some value to db:我正在尝试将一些值保存到数据库:
public void logFailure(Long objectID,Integer usLK){
StatusFailureDO failureDO = new StatusFailureDO(4,objectID, usLK);
failuresRepository.save(failureDO.getFailure());
}
@Repository
public interface FailuresRepository extends JpaRepository<GeneralFailure, Integer> {
GeneralFailure save(GeneralFailure aGeneralFailure);
void delete(GeneralFailure aGeneralFailure);
GeneralFailure findByObjectID(Long objectID);
}
There were many mapping errors and as such that I got pass now.有很多映射错误,因此我现在通过了。 I am trying to understand where in the process error occurs and what shall I look out for.我试图了解流程错误发生的位置以及我应该注意什么。
public class StatusFailureDO extends GeneralFailureDO implements Serializable
{
public StatusFailureDO(Integer failureTypeLK,Long objectID,
Integer usLK)
{
super(new StatusFailure(failureTypeLK,
"An exception occurred while trying to update an UploadStatus entry.",
objectID, usLK));
}
//more constructors and setters
}
public abstract class GeneralFailureDO implements ICISConstant, Serializable
{
private GeneralFailure mGeneralFailure;
//constructors and setters
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "GEN_FLR")
public class GeneralFailure implements Serializable,ICISConstant
{
@Column(name = "CRTN_TM")
private Date mCreationTime;
@Column(name = "TYP_LKP_ID")
private Integer failureTypeLK;
@Column(name = "STUS_LKP_ID")
private Integer mFailureStatusLK;
@Column(name="OBJ_ID")
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
@GenericGenerator(name = "native", strategy = "native")
private Long objectID;
@Column(name = "DSCR")
private String mDescription;
public Date getCreationTime()
{
return mCreationTime;
}
public void setCreationTime(Date aCreationTime)
{
mCreationTime = aCreationTime;
}
public String getDescription()
{
return mDescription;
}
public void setDescription(String aDescription)
{
if (aDescription != null && aDescription.length() > MAX_DESCRIPTION_LENGTH)
{
mDescription = aDescription.substring(0, MAX_DESCRIPTION_LENGTH);
}
else
{
mDescription = aDescription;
}
}
public Long getObjectID()
{
return objectID;
}
public void setObjectID(Long aObjectID)
{
objectID = aObjectID;
}
public Integer getFailureTypeLK()
{
return failureTypeLK;
}
public void setFailureTypeLK(Integer aFailureTypeLK)
{
failureTypeLK = aFailureTypeLK;
}
public Integer getFailureStatusLK()
{
return mFailureStatusLK;
}
public void setFailureStatusLK(Integer aFailureStatusLK)
{
mFailureStatusLK = aFailureStatusLK;
}
}
@Entity
@Table(name="STUS_FLR")
public class StatusFailure extends GeneralFailure implements Serializable
{
@Column(name = "STUS_OBJ_ID")
private Long mStatusObjectID;
@Column(name = "STUS_LKP_ID")
private Integer mStatusLK;
@Column(name = "RQST_TYP_LKP_ID")
private Integer mRequestTypeLK;
@Column(name = "CODE")
private String mCode;
@Column(name = "PST_TM")
private Timestamp mPostTime;
@Column(name = "MSG_SZ")
private Integer mMessageSize;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Collection<StatusFailureError> StatusFailureErrorList;
@Column(name = "SMPL_FLG")
private boolean mSimple;
public Integer getStatusLK()
{
return mStatusLK;
}
public void setStatusLK(Integer statusLK)
{
mStatusLK = statusLK;
}
public Long getStatusObjectID()
{
return mStatusObjectID;
}
public void setStatusObjectID(Long statusObjectID)
{
mStatusObjectID = statusObjectID;
}
public String getCode()
{
return mCode;
}
public void setCode(String aCode)
{
mCode = aCode;
}
public Collection<StatusFailureError> getStatusFailureErrorList()
{
return mStatusFailureErrorList;
}
public void setStatusFailureErrorList(
Collection<StatusFailureError> aStatusFailureErrorList)
{
mStatusFailureErrorList = aStatusFailureErrorList;
}
public void setErrorList(Collection<String> aErrorList)
{
if (aErrorList != null && !aErrorList.isEmpty())
{
mStatusFailureErrorList = new ArrayList<StatusFailureError>();
for (Iterator<String> iter = aErrorList.iterator(); iter.hasNext();)
{
String error = (String) iter.next();
StatusFailureError failureError = new StatusFailureError(this, error, getPostTime());
mStatusFailureErrorList.add(failureError);
}
}
else
{
mStatusFailureErrorList = null;
}
}
public Integer getMessageSize()
{
return mMessageSize;
}
public void setMessageSize(Integer aMessageSize)
{
mMessageSize = aMessageSize;
}
public Timestamp getPostTime()
{
return mPostTime;
}
public void setPostTime(Timestamp aPostTime)
{
mPostTime = aPostTime;
}
public Integer getRequestTypeLK()
{
return mRequestTypeLK;
}
public void setRequestTypeLK(Integer aRequestTypeLK)
{
mRequestTypeLK = aRequestTypeLK;
}
public boolean isSimple()
{
return mSimple;
}
public void setSimple(boolean aSimple)
{
mSimple = aSimple;
}
}
Any help is really appreciated.非常感谢任何帮助。
It is not obvious what the failureDO.getFailure()
returns exactly because you did not provide a method definition for the StatusFailureDO.getFailure()
method and so I will assume that that method returns an instance of a GeneralFailure
class (or StatusFailure that extends it). failureDO.getFailure()
返回的内容并不明显,因为您没有为StatusFailureDO.getFailure()
方法提供方法定义,因此我假设该方法返回GeneralFailure
class 的实例(或扩展它的 StatusFailure ).
For hibernate to successfully save objects into the database, the @Entity
classes that you are trying to save need to consist of "base" types.为了 hibernate 成功地将对象保存到数据库中,您尝试保存的@Entity
类需要包含“基本”类型。 I see that you have an object of class CLRISCache
defined in your GeneralFailure data class, that is most definitely not of a base type and not another @Entity
.我看到您在 GeneralFailure 数据 class 中定义了 class CLRISCache
的 object,这绝对不是基本类型,也不是另一个@Entity
。 You can prevent a field from being persisted by marking it with the @Transient
annotation, but really you should keep your data class pure.您可以通过使用@Transient
注释标记字段来防止字段被持久化,但实际上您应该保持数据 class 的纯净。
You can find a list of "base" types here: https://docs.jboss.org/hibernate/orm/5.0/mappingGuide/en-US/html/ch03.html您可以在此处找到“基本”类型列表: https://docs.jboss.org/hibernate/orm/5.0/mappingGuide/en-US/html/ch03.html
Actually I found the reason.其实我找到了原因。 The General failure has dateCreation variable of Date type and in mu status failure I had it as a timestamp. General failure 有 Date 类型的 dateCreation 变量,在 mu status failure 中我把它作为时间戳。 I need to make it to Date and it worked.我需要让它到 Date 并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.