weixin_43944282
weixin_43944282
2018-12-25 09:00

java.io.StreamCorruptedException: invalid stream header: 77327070是什么情况如何解决?

300
  • spring
  • java
  • hibernate
  • java-ee
  • eclipse

springboot+datajpa+sqlserver报Caused by: invalid stream header: 77327070是什么情况如何解决?

刚接触springboot+jpa的小白,拜求各路大神的帮忙:
开发工具是eclipse:
没写controller层,先用junit测试crud(即增删改查)中其中的修改和删除,不能用,代码如下:
实体编译好后
1.首先JpaRepository层用的完全是继承JpaRepository的借口自带方法,出查询外没用自定义任何修改:

@Repository

@Transactional

public interface sd extends JpaRepository{
Page findAll(Pageable pageable);

}

```2.service 层是:

@Override

@Modifying

@Transactional
public void delete(String pid) {
    // TODO Auto-generated method stub
    cd.deleteById(pid);
}

@Override
public boolean update(sd sf) {
    // TODO Auto-generated method stub
    cd.save(cfb);
    return true;
}

3.测试类中:

 @Test
 @Modifying
 @Transactional
public void deletepro()  {

    cps.delete("fef232");
}   

    @Test
public void querypro() {
    /* int page=1,size=10;
     Sort sort = new Sort(Direction.DESC, "pid");
     Pageable pageable = new PageRequest(page, size, sort);
     System.out.println(cps.findByPages(pageable));*/

}

``4.具体报错为:

org.hibernate.type.SerializationException: could not deserialize
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
.......(太长了懒得粘了省略)

**Caused by:

java.io.StreamCorruptedException: invalid stream header: 77327070
**

at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:866) ~[na:1.8.0_191]
at java.io.ObjectInputStream.(ObjectInputStream.java:358) ~[na:1.8.0_191]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.(SerializationHelper.java:309) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.(SerializationHelper.java:299) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
... 110 common frames omitted

5,配置用的是:application.properties 具体是:

#port is update
server.port=8080
#connection

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;DatabaseName=tzc12
spring.datasource.username=sa1
spring.datasource.password=qq
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.hibernate.ddl-auto = update

Naming strategy

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

#controller

spring.mvc.view.prefix=/

spring.mvc.view.suffix=.jsp
#Connection Pool
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false


除外,测试查询方法时junit未报错,但出现了以下情况是什么原因?如何解决:
JpaRepository层看最上面
service层:

@Override

    public Page<sd> findByPages(Pageable pageable) {
        // TODO Auto-generated method stub
        return  cd.findAll(pageable);
    }


@Test

    public void querypro() {

         int page=1,size=10;
         Sort sort = new Sort(Direction.DESC, "pid");
         Pageable pageable = new PageRequest(page, size, sort);
         System.out.println(cps.findByPages(pageable));

    }
    结果出来为:

    Page 2 of 1 containing UNKNOWN instances

    更新后:

    实体类:
    sd为主表,cds为附表,即cds 的主键是sd的外键。

    @Entity
@Table(name="cftbiop")
public class sd  implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 8786038170195933216L;



    @Id
    private  String     pid=(UUID.randomUUID().toString()) ;

    private  String     pname ;         

    private String introduction;

    private  String     marque; 

    private  String     showcase; 

    private String      waytoraise  ;   

    private  int        suppot; 

    private  int        raisefunds  ;

    private  int        goalnum    ;

    private cds showid;

    @ManyToOne
    @JoinColumn(name="showid")  
    public cds getShowid() {
        return showid;
    }

    public void setShowid(CFShowProspecification showid) {
        this.showid = showid;
    }
    private  boolean  homepagedisplay;

    private int price;  

    其余getter,setter省略不粘了,都已getter,setter,

    测试查询方法,把page改为0后,报了和删除,修改一样的错误
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐

  • Java socket通信
    • it技术
    • 互联网问答
    • IT行业问题
    • 计算机技术
    • 编程语言问答
    • 0个回答