org.hibernate.type.SerializationException:尝试将数据保存到postgresl表

时间:2017-07-16 14:22:58

标签: java spring hibernate jpa serialization

我在尝试将itemLocations字段保存到表中时遇到了spring jpa异常。     包com.tgt.scmd.inbound.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Arrays;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import com.tgt.scmd.inbound.utils.RequestStatus;
@Entity
@Table(name = "breakpack_authorization_details")
public class SupplyChainBreakPackAuth implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = -5688043643278441710L;

    @Id
    @SequenceGenerator(name = "break_pack_auth_seq", sequenceName = "break_pack_auth_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "break_pack_auth_seq")
    private int id;

    private ItemLocations[] itemLocations;

    @Column(updatable = false)
    @CreationTimestamp
    private Timestamp requestedDate;

    private String requestReason;

    private String requestor;

    private String department;

    private String itemStatus;

    private String reasonForFailure;

    private String approversReason;

    private String approver;

    private String assortmentAnalysisDeptId;

    private String assortmentAnalysisDescription;

    private RequestStatus requestStatus;

    @UpdateTimestamp
    private Timestamp modifiedDate;


    public Integer getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public ItemLocations[] getItemLocations() {
        return itemLocations;
    }
    public void setItemLocations(ItemLocations[] itemLocations) {
        this.itemLocations = itemLocations;
    }
    public String getApprover() {
        return approver;
    }

    public void setApprover(String approver) {
        this.approver = approver;
    }

    public RequestStatus getRequestStatus() {
        return requestStatus;
    }

    public void setRequestStatus(RequestStatus requestStatus) {
        this.requestStatus = requestStatus;
    }

    public Timestamp getRequestedDate() {
        return requestedDate;
    }

    public void setRequestedDate(Timestamp requestedDate) {
        this.requestedDate = requestedDate;
    }

    public String getRequestReason() {
        return requestReason;
    }

    public void setRequestReason(String requestReason) {
        this.requestReason = requestReason;
    }

    public String getRequestor() {
        return requestor;
    }

    public void setRequestor(String requestor) {
        this.requestor = requestor;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getItemStatus() {
        return itemStatus;
    }

    public void setItemStatus(String itemStatus) {
        this.itemStatus = itemStatus;
    }

    public String getReasonForFailure() {
        return reasonForFailure;
    }

    public void setReasonForFailure(String reasonForFailure) {
        this.reasonForFailure = reasonForFailure;
    }

    public String getApproversReason() {
        return approversReason;
    }

    public void setApproversReason(String approversReason) {
        this.approversReason = approversReason;
    }

    public String getAssortmentAnalysisDeptId() {
        return assortmentAnalysisDeptId;
    }

    public void setAssortmentAnalysisDeptId(String assortmentAnalysisDeptId) {
        this.assortmentAnalysisDeptId = assortmentAnalysisDeptId;
    }

    public String getAssortmentAnalysisDescription() {
        return assortmentAnalysisDescription;
    }

    public void setAssortmentAnalysisDescription(
            String assortmentAnalysisDescription) {
        this.assortmentAnalysisDescription = assortmentAnalysisDescription;
    }

    public Timestamp getModifiedDate() {
        return modifiedDate;
    }
    public void setModifiedDate(Timestamp modifiedDate) {
        this.modifiedDate = modifiedDate;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((approver == null) ? 0 : approver.hashCode());
        result = prime * result
                + ((approversReason == null) ? 0 : approversReason.hashCode());
        result = prime
                * result
                + ((assortmentAnalysisDeptId == null) ? 0
                        : assortmentAnalysisDeptId.hashCode());
        result = prime
                * result
                + ((assortmentAnalysisDescription == null) ? 0
                        : assortmentAnalysisDescription.hashCode());
        result = prime * result
                + ((department == null) ? 0 : department.hashCode());
        result = prime * result + id;
        result = prime * result
                + ((itemLocations == null) ? 0 : itemLocations.hashCode());
        result = prime * result
                + ((itemStatus == null) ? 0 : itemStatus.hashCode());
        result = prime * result
                + ((modifiedDate == null) ? 0 : modifiedDate.hashCode());
        result = prime
                * result
                + ((reasonForFailure == null) ? 0 : reasonForFailure.hashCode());
        result = prime * result
                + ((requestReason == null) ? 0 : requestReason.hashCode());
        result = prime * result
                + ((requestStatus == null) ? 0 : requestStatus.hashCode());
        result = prime * result
                + ((requestedDate == null) ? 0 : requestedDate.hashCode());
        result = prime * result
                + ((requestor == null) ? 0 : requestor.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        SupplyChainBreakPackAuth other = (SupplyChainBreakPackAuth) obj;
        if (approver == null) {
            if (other.approver != null)
                return false;
        } else if (!approver.equals(other.approver))
            return false;
        if (approversReason == null) {
            if (other.approversReason != null)
                return false;
        } else if (!approversReason.equals(other.approversReason))
            return false;
        if (assortmentAnalysisDeptId == null) {
            if (other.assortmentAnalysisDeptId != null)
                return false;
        } else if (!assortmentAnalysisDeptId
                .equals(other.assortmentAnalysisDeptId))
            return false;
        if (assortmentAnalysisDescription == null) {
            if (other.assortmentAnalysisDescription != null)
                return false;
        } else if (!assortmentAnalysisDescription
                .equals(other.assortmentAnalysisDescription))
            return false;
        if (department == null) {
            if (other.department != null)
                return false;
        } else if (!department.equals(other.department))
            return false;
        if (id != other.id)
            return false;
        if (itemLocations == null) {
            if (other.itemLocations != null)
                return false;
        } else if (!itemLocations.equals(other.itemLocations))
            return false;
        if (itemStatus == null) {
            if (other.itemStatus != null)
                return false;
        } else if (!itemStatus.equals(other.itemStatus))
            return false;
        if (modifiedDate == null) {
            if (other.modifiedDate != null)
                return false;
        } else if (!modifiedDate.equals(other.modifiedDate))
            return false;
        if (reasonForFailure == null) {
            if (other.reasonForFailure != null)
                return false;
        } else if (!reasonForFailure.equals(other.reasonForFailure))
            return false;
        if (requestReason == null) {
            if (other.requestReason != null)
                return false;
        } else if (!requestReason.equals(other.requestReason))
            return false;
        if (requestStatus != other.requestStatus)
            return false;
        if (requestedDate == null) {
            if (other.requestedDate != null)
                return false;
        } else if (!requestedDate.equals(other.requestedDate))
            return false;
        if (requestor == null) {
            if (other.requestor != null)
                return false;
        } else if (!requestor.equals(other.requestor))
            return false;
        return true;
    }


    public static class ItemLocations{
        private String tcin;

        private Integer[] locationIds;

        public String getTcin() {
            return tcin;
        }

        public void setTcin(String tcin) {
            this.tcin = tcin;
        }

        public Integer[] getLocationIds() {
            return locationIds;
        }

        public void setLocationIds(Integer[] locationIds) {
            this.locationIds = locationIds;
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + Arrays.hashCode(locationIds);
            result = prime * result + ((tcin == null) ? 0 : tcin.hashCode());
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            ItemLocations other = (ItemLocations) obj;
            if (!Arrays.equals(locationIds, other.locationIds))
                return false;
            if (tcin == null) {
                if (other.tcin != null)
                    return false;
            } else if (!tcin.equals(other.tcin))
                return false;
            return true;
        }
    }

}

当我尝试对其执行hibernate保存操作时,它会抛出不可序列化的异常。确切的例外情况如下:

  

引起:org.hibernate.type.SerializationException:无法序列化       在org.hibernate.internal.util.SerializationHelper.serialize(SerializationHelper.java:119)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.internal.util.SerializationHelper.serialize(SerializationHelper.java:144)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.internal.util.SerializationHelper.clone(SerializationHelper.java:75)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.type.descriptor.java.SerializableTypeDescriptor $ SerializableMutabilityPlan.deepCopyNotNull(SerializableTypeDescriptor.java:43)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       at org.hibernate.type.descriptor.java.SerializableTypeDescriptor $ SerializableMutabilityPlan.deepCopyNotNull(SerializableTypeDescriptor.java:30)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.type.descriptor.java.MutableMutabilityPlan.deepCopy(MutableMutabilityPlan.java:35)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:283)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:279)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:51)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:178)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)〜[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:775)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.internal.SessionImpl.persist(SessionImpl.java:748)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:753)~ [hibernate-core-5.0.12.Final.jar:5.0.12.Final]       在org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1146)〜[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_121]       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_121]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_121]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_121]       在org.springframework.orm.jpa.ExtendedEntityManagerCreator $ ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347)~ [spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]       at com.sun.proxy。$ Proxy101.persist(Unknown Source)〜[na:na]       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_121]       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_121]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_121]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_121]       在org.springframework.orm.jpa.SharedEntityManagerCreator $ SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298)〜[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]       at com.sun.proxy。$ Proxy101.persist(Unknown Source)〜[na:na]       在org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:508)〜[spring-data-jpa-1.11.1.RELEASE.jar:na]       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_121]       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_121]       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_121]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_121]       在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:504)〜[spring-data-commons-1.13.1.RELEASE.jar:na]       在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:489)〜[spring-data-commons-1.13.1.RELEASE.jar:na]       在org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)〜[spring-data-commons-1.13.1.RELEASE.jar:na]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)〜[spring-data-commons-1.13.1.RELEASE.jar:na]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:99)〜[spring-tx-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)〜[spring-tx-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)〜[spring-tx-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]       在org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)〜[spring-tx-4.3.7.RELEASE.jar:4.3.7.RELEASE]       ...省略了85个常见帧   引起:java.io.NotSerializableException:com.tgt.scmd.inbound.domain.SupplyChainBreakPackAuth $ ItemLocations       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)〜[na:1.8.0_121]       在java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)〜[na:1.8.0_121]       在java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)〜[na:1.8.0_121]       在java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)〜[na:1.8.0_121]       在org.hibernate.internal.util.SerializationHelper.serialize(SerializationHelper.java:115)〜[hibernate-core-5.0.12.Final.jar:5.0.12.Final]       ...省略了132个常见帧

0 个答案:

没有答案