简体   繁体   English

无法序列化; 嵌套异常是 org.hibernate.type.SerializationException: 无法序列化

[英]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.

相关问题 嵌套异常是 org.hibernate.type.SerializationException:无法反序列化 - nested exception is org.hibernate.type.SerializationException: could not deserialize 请求处理失败; 嵌套异常是 org.hibernate.type.SerializationException:无法反序列化 - Request processing failed; nested exception is org.hibernate.type.SerializationException: could not deserialize 使用数据库 H2 的 Java Spring Boot Jpa Hibernate 中的错误。 错误:无法反序列化; 嵌套异常是 org.hibernate.type.SerializationException - ERROR in Java Spring Boot Jpa Hibernate using database H2. ERROR: could not deserialize; nested exception is org.hibernate.type.SerializationException org.hibernate.type.SerializationException:无法在 Hibernate 代码中反序列化 - org.hibernate.type.SerializationException: could not deserialize in Hibernate code 无法摆脱org.hibernate.type.SerializationException:无法反序列化 - impossible to get rid off org.hibernate.type.SerializationException: could not deserialize Hibernate SerializationException:无法反序列化 - Hibernate SerializationException: could not deserialize 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行查询 - nested exception is org.hibernate.exception.SQLGrammarException: could not execute query 无法打开 Hibernate Session 进行事务; 嵌套异常是 org.hibernate.exception.JDBCConnectionException:无法打开连接 - Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection 嵌套的异常是org.hibernate.PropertyAccessException:无法设置字段值 - nested exception is org.hibernate.PropertyAccessException: Could not set field value 无法构建 Hibernate SessionFactory; 嵌套异常是 org.hibernate.MappingException:无法确定类型:java.util.Set,在表中: - Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, at table:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM