如何解决Hibernate org.hibernate.type.SerializationException?

时间:2016-09-27 13:21:10

标签: java spring hibernate spring-boot

在我的Spring Boot应用程序控制器中,我按以下方式处理Update操作:

@RestController
public class DirpartytableController {
    @Autowired
    SpringBootKafkaProducer springBootKafkaProducer;

    @RequestMapping(value="/dirpartytable", method=RequestMethod.POST)
    @ResponseBody
    public String handleRecords(@RequestBody String dirpartytable) throws JSONException, JsonParseException, JsonMappingException, IOException {

        ObjectMapper mapper = new ObjectMapper();
        //mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);

        String s = dirpartytable;
        String s1 = s;

        JSONArray jsonArray = new JSONArray(dirpartytable);

        for (int i = 0; i < jsonArray.length(); i++) {

            JSONObject dptObject = jsonArray.getJSONObject(i);

            Dirpartytable dpt = mapper.readValue(dptObject.toString(), new TypeReference<Dirpartytable>(){});

            Long recid = dpt.getUpk_keyfieldrecid();

            Long partition = dpt.getUpk_partition();

            String optype = dpt.getUpk_changeoperation();

            if(optype.equals("U")) {
            Dirpartytable table = (Dirpartytable) dirpartytableDao.getById(Dirpartytable.class, 
                    new DirpartytableCompositeKey 
                    (recid, partition));

            table.setUpk_captureddate(dpt.getUpk_captureddate());
            table.setUpk_partition(dpt.getUpk_partition());
            table.setUpk_changedtablename(dpt.getUpk_changedtablename());
            table.setUpk_changeoperation(dpt.getUpk_changeoperation());
            table.setUpk_keyfieldrecid(dpt.getUpk_keyfieldrecid());

            BeanUtils.copyProperties(dpt, table);

            table.setDirpartytableCompositeKey(new DirpartytableCompositeKey 
                    (dpt.getUpk_keyfieldrecid(),dpt.getUpk_partition()));
                dirpartytableDao.update(table);
                }
        }

当此特定行执行时(从Postgres实际检索实体):

    Dirpartytable table = (Dirpartytable) dirpartytableDao.getById(Dirpartytable.class, 
                        new DirpartytableCompositeKey 
                        (recid, partition));

我收到以下异常:

2016-09-27 07:35:57.218 ERROR 62250 --- [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.StreamCorruptedException: invalid stream header: 31393030
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:301)

这是我的Dirpartytable课程:

@Entity
public class Dirpartytable implements java.io.Serializable {

    @EmbeddedId
      private DirpartytableCompositeKey key;

    @Transient
    private String optype;


    @Transient
    private Date upk_captureddate;
    @Transient
    private Long upk_partition; 
    @Transient
    private String upk_changedtablename;
    @Transient
    private String upk_changeoperation;
    @Transient
    private Long upk_keyfieldrecid;
    @Transient
    private String upk_accountnum;
    @Transient
    private String upk_dataareaid;

    private String businessactivity_sa;
    private String businessactivitydesc_sa;
    private String filenumber_sa;
    private Long companynafcode;
    private String businessnumber_ca;
    private String softwareidentificationcode_ca;
    private String fiscalcode_it;
    private Integer companytype_mx;
    private String rfc_mx;
    private String curp_mx;
    private String stateinscription_mx;
    private Integer legalnature_it;
    private String bank;
    private String giro;
    private String regnum;
    private String coregnum;
    private String vatnum;
    private String importvatnum;
    private String upsnum;
    private String tax1099regnum;
    private String namecontrol;
    private String tcc;
    private String dvrid;
    private String intrastatcode;
    private String girocontract;
    private String girocontractaccount;
    private String branchid;
    private String vatnumbranchid;
    private String importvatnumbranchid;
    private String activitycode;
    private Date conversiondate;
    private String addrformat;
    private String companyregcomfr;
    private String packmaterialfeelicensenum;
    private String paymroutingdnb;
    private String paymtradernumber;
    private String issuingsignature;
    private String siacode;
    private String bankcentralbankpurposecode;
    private String bankcentralbankpurposetext;
    private String dba;
    private Integer foreignentityindicator;
    private Integer combinedfedstatefiler;
    private Integer lastfilingindicator;
    private Integer validate1099onentry;
    private String legalformfr;
    private String shippingcalendarid;
    private String enterprisenumber;
    private String branchnumber;
    private String customscustomernumber_fi;
    private String customslicensenumber_fi;
    private String dataarea;
    private Integer planningcompany;
    private String taxrepresentative;
    private String orgid;
    private String bankacctusedfor1099;
    private Long payminstruction1;
    private Long payminstruction2;
    private Long payminstruction3;
    private Long payminstruction4;
    private String legalrepresentativename_mx;
    private String legalrepresentativerfc_mx;
    private String legalrepresentativecurp_mx;
    private String ficreditorid_dk;
    private Integer isconsolidationcompany;
    private Integer iseliminationcompany;
    private String accountingpersonnel_jp;
    private String templatefolder_w;
    private String companyrepresentative_jp;
    private String cnae_br;
    private Integer resident_w;
    private String pfregnum_ru;
    private String raliencorpcountry;
    private String raliencorpname;
    private String rfullname;
    private String enterprisecode;
    private String commercialregistersection;
    private String commercialregisterinsetnumber;
    private String commercialregister;
    private String fss_ru;
    private String organizationlegalform_ru;
    private String subordinatecode;
    private String fssaccount_ru;
    private String accountant_lt;
    private String accountofficerefnum;
    private Date businesscommenceddate_jp;
    private BigDecimal businessinitialcapital_jp;
    private String businessitem_jp;
    private String certifiedtaxaccountant_jp;
    private String cuc_it;
    private String head_lt;
    private String legalrepresentative_jp;
    private String personincharge_jp;
    private Integer printcorrinvoicelabe_de;
    private Date printcorrinvoicelabeleffdateDe;
    private Integer printenterpriseregister_no;
    private Integer printinnkppinaddress_ru;
    private String taxauthority_ru;
    private Integer organizationtype;
    private Integer omoperatingunittype;
    private Long hcmworker;
    private String omoperatingunitnumber;
    private String initials;
    private String childrennames;
    private Integer maritalstatus;
    private String hobbies;
    private Integer gender;
    private Long namesequence;
    private String phoneticfirstname;
    private String phoneticmiddlename;
    private String phoneticlastname;
    private Long personaltitle;
    private Long personalsuffix;
    private String professionaltitle;
    private String professionalsuffix;
    private Integer birthmonth;
    private Integer birthday;
    private Integer birthyear;
    private Integer anniversarymonth;
    private Integer anniversaryday;
    private Integer anniversaryyear;
    private Long communicatorsignin;
    private Integer numberofemployees;
    private String orgnumber;
    private Integer abc;
    private Long teammembershipcriterion;
    private String description;
    private Integer isactive;
    private String teamadministrator;
    private String phoneticname;
    private Long dunsnumberrecid;
    private String name;
    private String languageid;
    private String namealias;
    private String partynumber;
    private long instancerelationtype;
    private String knownas;
    private long primaryaddresslocation;
    private long primarycontactemail;
    private long primarycontactfax;
    private long primarycontactphone;
    private long primarycontacttelex;
    private long primarycontacturl;
    private Date modifieddatetime;
    private String modifiedby;
    private Date createddatetime;
    private String createdby;
    private int recversion;
    private long relationtype;
    private Integer eeenablepersonaldatareadlog;
    private LocalTime printcorrinvoicelabeleffdate_de;
    private Integer key_;

//I have getters and setters accordingly

这是我的DirpartytableCompositeKey类:

public class DirpartytableCompositeKey implements Serializable{
    @Column(name = "recid")
      private Long recid;

      @Column(name = "partition")
      private Long partition;

      public DirpartytableCompositeKey() {
        }

      public void setRecid(Long recid){
          this.recid = recid;
      }

      public void setPartition(Long partition){
          this.partition=partition;
      }

      public DirpartytableCompositeKey(Long recid, long partition) {
            this.recid = recid;
            this.partition = partition;
        }

这是相应的Postgres表:

/*
CREATE TABLE "dbo"."dirpartytable" (
    "businessactivity_sa" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "businessactivitydesc_sa" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "filenumber_sa" varchar(15) DEFAULT 'NULL'::character varying COLLATE "default",
    "companynafcode" int8,
    "businessnumber_ca" varchar(9) DEFAULT 'NULL'::character varying COLLATE "default",
    "softwareidentificationcode_ca" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "fiscalcode_it" varchar(11) DEFAULT 'NULL'::character varying COLLATE "default",
    "companytype_mx" int4 DEFAULT 0,
    "rfc_mx" varchar(13) DEFAULT 'NULL'::character varying COLLATE "default",
    "curp_mx" varchar(18) DEFAULT 'NULL'::character varying COLLATE "default",
    "stateinscription_mx" varchar(30) DEFAULT 'NULL'::character varying COLLATE "default",
    "legalnature_it" int4 DEFAULT 0,
    "bank" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "giro" varchar(35) DEFAULT 'NULL'::character varying COLLATE "default",
    "regnum" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "coregnum" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "vatnum" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "importvatnum" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "upsnum" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "tax1099regnum" varchar(11) DEFAULT 'NULL'::character varying COLLATE "default",
    "namecontrol" varchar(4) DEFAULT 'NULL'::character varying COLLATE "default",
    "tcc" varchar(5) DEFAULT 'NULL'::character varying COLLATE "default",
    "key_" int4 DEFAULT 0,
    "dvrid" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "intrastatcode" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "girocontract" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "girocontractaccount" varchar(11) DEFAULT 'NULL'::character varying COLLATE "default",
    "branchid" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "vatnumbranchid" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "importvatnumbranchid" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "activitycode" varchar(9) DEFAULT 'NULL'::character varying COLLATE "default",
    "conversiondate" timestamp(6) NULL,
    "addrformat" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "companyregcomfr" varchar(30) DEFAULT 'NULL'::character varying COLLATE "default",
    "packmaterialfeelicensenum" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "paymroutingdnb" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "paymtradernumber" varchar(4) DEFAULT 'NULL'::character varying COLLATE "default",
    "issuingsignature" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "siacode" varchar(5) DEFAULT 'NULL'::character varying COLLATE "default",
    "bankcentralbankpurposecode" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "bankcentralbankpurposetext" varchar(140) DEFAULT 'NULL'::character varying COLLATE "default",
    "dba" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "foreignentityindicator" int4 DEFAULT 0,
    "combinedfedstatefiler" int4 DEFAULT 0,
    "lastfilingindicator" int4 DEFAULT 0,
    "validate1099onentry" int4 DEFAULT 0,
    "legalformfr" varchar(100) DEFAULT 'NULL'::character varying COLLATE "default",
    "shippingcalendarid" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "enterprisenumber" varchar(50) DEFAULT 'NULL'::character varying COLLATE "default",
    "branchnumber" varchar(13) DEFAULT 'NULL'::character varying COLLATE "default",
    "customscustomernumber_fi" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "customslicensenumber_fi" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "dataarea" varchar(4) DEFAULT 'NULL'::character varying COLLATE "default",
    "planningcompany" int4 DEFAULT 0,
    "taxrepresentative" varchar(45) DEFAULT 'NULL'::character varying COLLATE "default",
    "orgid" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "bankacctusedfor1099" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "payminstruction1" int8,
    "payminstruction2" int8,
    "payminstruction3" int8,
    "payminstruction4" int8,
    "legalrepresentativename_mx" varchar(50) DEFAULT 'NULL'::character varying COLLATE "default",
    "legalrepresentativerfc_mx" varchar(13) DEFAULT 'NULL'::character varying COLLATE "default",
    "legalrepresentativecurp_mx" varchar(18) DEFAULT 'NULL'::character varying COLLATE "default",
    "ficreditorid_dk" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "isconsolidationcompany" int4 DEFAULT 0,
    "iseliminationcompany" int4 DEFAULT 0,
    "accountingpersonnel_jp" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "templatefolder_w" varchar(259) DEFAULT 'NULL'::character varying COLLATE "default",
    "companyrepresentative_jp" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "cnae_br" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "resident_w" int4 DEFAULT 0,
    "pfregnum_ru" varchar(14) DEFAULT 'NULL'::character varying COLLATE "default",
    "raliencorpcountry" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "raliencorpname" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "rfullname" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "enterprisecode" varchar(50) DEFAULT 'NULL'::character varying COLLATE "default",
    "commercialregistersection" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "commercialregisterinsetnumber" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "commercialregister" varchar(40) DEFAULT 'NULL'::character varying COLLATE "default",
    "fss_ru" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "organizationlegalform_ru" varchar(40) DEFAULT 'NULL'::character varying COLLATE "default",
    "subordinatecode" varchar(5) DEFAULT 'NULL'::character varying COLLATE "default",
    "fssaccount_ru" varchar(20) DEFAULT 'NULL'::character varying COLLATE "default",
    "accountant_lt" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "accountofficerefnum" varchar(13) DEFAULT 'NULL'::character varying COLLATE "default",
    "businesscommenceddate_jp" timestamp(6) NULL,
    "businessinitialcapital_jp" numeric(34,16),
    "businessitem_jp" varchar(30) DEFAULT 'NULL'::character varying COLLATE "default",
    "certifiedtaxaccountant_jp" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "cuc_it" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "head_lt" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "legalrepresentative_jp" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "personincharge_jp" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "printcorrinvoicelabel_de" int4 DEFAULT 0,
    "printcorrinvoicelabeleffdate_de" timestamp(6) NULL,
    "printenterpriseregister_no" int4 DEFAULT 0,
    "printinnkppinaddress_ru" int4 DEFAULT 0,
    "taxauthority_ru" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "organizationtype" int4 DEFAULT 0,
    "omoperatingunittype" int4 DEFAULT 0,
    "hcmworker" int8,
    "omoperatingunitnumber" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "initials" varchar(10) DEFAULT 'NULL'::character varying COLLATE "default",
    "childrennames" varchar(150) DEFAULT 'NULL'::character varying COLLATE "default",
    "maritalstatus" int4 DEFAULT 0,
    "hobbies" varchar(150) DEFAULT 'NULL'::character varying COLLATE "default",
    "gender" int4 DEFAULT 0,
    "namesequence" int8,
    "phoneticfirstname" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "phoneticmiddlename" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "phoneticlastname" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "personaltitle" int8,
    "personalsuffix" int8,
    "professionaltitle" varchar(50) DEFAULT 'NULL'::character varying COLLATE "default",
    "professionalsuffix" varchar(50) DEFAULT 'NULL'::character varying COLLATE "default",
    "birthmonth" int4 DEFAULT 0,
    "birthday" int4 DEFAULT 0,
    "birthyear" int4 DEFAULT 0,
    "anniversarymonth" int4 DEFAULT 0,
    "anniversaryday" int4 DEFAULT 0,
    "anniversaryyear" int4 DEFAULT 0,
    "communicatorsignin" int8,
    "numberofemployees" int4 DEFAULT 0,
    "orgnumber" varchar(25) DEFAULT 'NULL'::character varying COLLATE "default",
    "abc" int4 DEFAULT 0,
    "teammembershipcriterion" int8,
    "description" varchar(60) DEFAULT 'NULL'::character varying COLLATE "default",
    "isactive" int4 DEFAULT 0,
    "teamadministrator" varchar(8) DEFAULT 'NULL'::character varying COLLATE "default",
    "phoneticname" varchar(100) DEFAULT 'NULL'::character varying COLLATE "default",
    "dunsnumberrecid" int8,
    "name" varchar(100) NOT NULL DEFAULT ''''''::character varying COLLATE "default",
    "languageid" varchar(7) NOT NULL DEFAULT ''''''::character varying COLLATE "default",
    "namealias" varchar(20) NOT NULL DEFAULT ''''''::character varying COLLATE "default",
    "partynumber" varchar(40) NOT NULL DEFAULT ''''''::character varying COLLATE "default",
    "instancerelationtype" int8 NOT NULL,
    "knownas" varchar(100) NOT NULL DEFAULT ''''''::character varying COLLATE "default",
    "primaryaddresslocation" int8 NOT NULL,
    "primarycontactemail" int8 NOT NULL,
    "primarycontactfax" int8 NOT NULL,
    "primarycontactphone" int8 NOT NULL,
    "primarycontacttelex" int8 NOT NULL,
    "primarycontacturl" int8 NOT NULL,
    "modifieddatetime" timestamp(6) NOT NULL,
    "modifiedby" varchar(8) NOT NULL DEFAULT '?'::character varying COLLATE "default",
    "createddatetime" timestamp(6) NOT NULL,
    "createdby" varchar(8) NOT NULL DEFAULT '?'::character varying COLLATE "default",
    "recversion" int4 NOT NULL DEFAULT 1,
    "relationtype" int8 NOT NULL,
    "partition" int8 NOT NULL,
    "recid" int8 NOT NULL,
    "eeenablepersonaldatareadlog" int4 DEFAULT 0
)
WITH (OIDS=TRUE);

我该怎么做才能解决Hibernate SerializationException?

0 个答案:

没有答案