Home > Software design >  could not serialize; nested exception is org.hibernate.type.SerializationException: could not serial
could not serialize; nested exception is org.hibernate.type.SerializationException: could not serial

Time:01-24

I have spend way too much find finding the root cause of the below error:

org.springframework.orm.jpa.JpaSystemException: could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize

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.

CodePudding user response:

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).

For hibernate to successfully save objects into the database, the @Entity classes that you are trying to save need to consist of "base" types. 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. You can prevent a field from being persisted by marking it with the @Transient annotation, but really you should keep your data class pure.

You can find a list of "base" types here: https://docs.jboss.org/hibernate/orm/5.0/mappingGuide/en-US/html/ch03.html

CodePudding user response:

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. I need to make it to Date and it worked.

  • Related