Hibernate错误:不能反序列化could not deserialize 在是用HQL语言查询的过程中出现如下错误:org.hibernate.type.SerializationException: could not deserializeCaused by: java.io.StreamCorruptedException: invalid stream header: 32003000估计是在映射文件,实体类和数据库表中出错,但不找不出什么原因........H 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你的代码详细代码发过来。可能触发的原因:1,ORM映射,你的hibernate映射文件里面的是否和你实体类对应,表的字段是否对应。2,实体类是否序列化。 //Post.java@Entity@Table(name = "posts", schema = "dbo", catalog = "JavaSystem")public class Posts implements java.io.Serializable { private int pid; private String ptitle; private String pauther; private Serializable pdate; private Set<Replys> replyses = new HashSet<Replys>(0); public Posts() { } public Posts(int pid) { this.pid = pid; } public Posts(int pid, String ptitle, String pauther, Serializable pdate, Set<Replys> replyses) { this.pid = pid; this.ptitle = ptitle; this.pauther = pauther; this.pdate = pdate; this.replyses = replyses; } @Id @Column(name = "pid", unique = true, nullable = false) public int getPid() { return this.pid; } public void setPid(int pid) { this.pid = pid; } @Column(name = "ptitle") public String getPtitle() { return this.ptitle; } public void setPtitle(String ptitle) { this.ptitle = ptitle; } @Column(name = "pauther", length = 20) public String getPauther() { return this.pauther; } public void setPauther(String pauther) { this.pauther = pauther; } @Column(name = "pdate") public Serializable getPdate() { return this.pdate; } public void setPdate(Serializable pdate) { this.pdate = pdate; } @OneToMany(fetch = FetchType.LAZY, mappedBy = "posts") public Set<Replys> getReplyses() { return this.replyses; } public void setReplyses(Set<Replys> replyses) { this.replyses = replyses; }}//Replys.java@Entity@Table(name = "replys", schema = "dbo", catalog = "JavaSystem")public class Replys implements java.io.Serializable { private int replyid; private Posts posts; private String rcont; private String rauther; private Serializable rdate; public Replys() { } public Replys(int replyid) { this.replyid = replyid; } public Replys(int replyid, Posts posts, String rcont, String rauther, Serializable rdate) { this.replyid = replyid; this.posts = posts; this.rcont = rcont; this.rauther = rauther; this.rdate = rdate; } @Id @Column(name = "replyid", unique = true, nullable = false) public int getReplyid() { return this.replyid; } public void setReplyid(int replyid) { this.replyid = replyid; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "pid") public Posts getPosts() { return this.posts; } public void setPosts(Posts posts) { this.posts = posts; } @Column(name = "rcont") public String getRcont() { return this.rcont; } public void setRcont(String rcont) { this.rcont = rcont; } @Column(name = "rauther", length = 10) public String getRauther() { return this.rauther; } public void setRauther(String rauther) { this.rauther = rauther; } @Column(name = "rdate") public Serializable getRdate() { return this.rdate; } public void setRdate(Serializable rdate) { this.rdate = rdate; }} //Posts.hbm.xml<hibernate-mapping> <class name="com.guet.bean.Posts" table="posts" schema="dbo" catalog="JavaSystem"> <id name="pid" type="int"> <column name="pid" /> <generator class="assigned" /> </id> <property name="ptitle" type="string"> <column name="ptitle" /> </property> <property name="pauther" type="string"> <column name="pauther" length="20" /> </property> <property name="pdate" type="serializable"> <column name="pdate" /> </property> <set name="replyses" table="replys" inverse="true" lazy="true" fetch="select"> <key> <column name="pid" /> </key> <one-to-many class="com.guet.bean.Replys" /> </set> </class></hibernate-mapping>//Replys.hbm.xml<hibernate-mapping> <class name="com.guet.bean.Replys" table="replys" schema="dbo" catalog="JavaSystem"> <id name="replyid" type="int"> <column name="replyid" /> <generator class="assigned" /> </id> <many-to-one name="posts" class="com.guet.bean.Posts" fetch="select"> <column name="pid" /> </many-to-one> <property name="rcont" type="string"> <column name="rcont" /> </property> <property name="rauther" type="string"> <column name="rauther" length="10" /> </property> <property name="rdate" type="serializable"> <column name="rdate" /> </property> </class></hibernate-mapping> posts表replys表replys表的pid为posts表pid的外键 servelt的部署小问题。。。 【江湖求助啊。。。】毕业设计遇到的难点,求高手进来支招。。 HQL 查询效率问题 struts2上传图片的问题 关Apache服务的简单问题 struts 问题 J2EE配置环境详细说明(新手) 请解释一下j2ee,ejb,jms各是什么 应用服务器之选择? org.hibernate.exception.JDBCConnectionException: Cannot open connection SSH框架下如何实现文件下载 <c:forEach>循环List<map<List<a>>,list<b>> 求大神啊!!!
可能触发的原因:
1,ORM映射,你的hibernate映射文件里面的是否和你实体类对应,表的字段是否对应。
2,实体类是否序列化。
//Post.java
@Entity
@Table(name = "posts", schema = "dbo", catalog = "JavaSystem")
public class Posts implements java.io.Serializable { private int pid;
private String ptitle;
private String pauther;
private Serializable pdate;
private Set<Replys> replyses = new HashSet<Replys>(0); public Posts() {
} public Posts(int pid) {
this.pid = pid;
} public Posts(int pid, String ptitle, String pauther, Serializable pdate,
Set<Replys> replyses) {
this.pid = pid;
this.ptitle = ptitle;
this.pauther = pauther;
this.pdate = pdate;
this.replyses = replyses;
} @Id
@Column(name = "pid", unique = true, nullable = false)
public int getPid() {
return this.pid;
} public void setPid(int pid) {
this.pid = pid;
} @Column(name = "ptitle")
public String getPtitle() {
return this.ptitle;
} public void setPtitle(String ptitle) {
this.ptitle = ptitle;
} @Column(name = "pauther", length = 20)
public String getPauther() {
return this.pauther;
} public void setPauther(String pauther) {
this.pauther = pauther;
} @Column(name = "pdate")
public Serializable getPdate() {
return this.pdate;
} public void setPdate(Serializable pdate) {
this.pdate = pdate;
} @OneToMany(fetch = FetchType.LAZY, mappedBy = "posts")
public Set<Replys> getReplyses() {
return this.replyses;
} public void setReplyses(Set<Replys> replyses) {
this.replyses = replyses;
}}
//Replys.java
@Entity
@Table(name = "replys", schema = "dbo", catalog = "JavaSystem")
public class Replys implements java.io.Serializable { private int replyid;
private Posts posts;
private String rcont;
private String rauther;
private Serializable rdate; public Replys() {
} public Replys(int replyid) {
this.replyid = replyid;
} public Replys(int replyid, Posts posts, String rcont, String rauther,
Serializable rdate) {
this.replyid = replyid;
this.posts = posts;
this.rcont = rcont;
this.rauther = rauther;
this.rdate = rdate;
} @Id
@Column(name = "replyid", unique = true, nullable = false)
public int getReplyid() {
return this.replyid;
} public void setReplyid(int replyid) {
this.replyid = replyid;
} @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pid")
public Posts getPosts() {
return this.posts;
} public void setPosts(Posts posts) {
this.posts = posts;
} @Column(name = "rcont")
public String getRcont() {
return this.rcont;
} public void setRcont(String rcont) {
this.rcont = rcont;
} @Column(name = "rauther", length = 10)
public String getRauther() {
return this.rauther;
} public void setRauther(String rauther) {
this.rauther = rauther;
} @Column(name = "rdate")
public Serializable getRdate() {
return this.rdate;
} public void setRdate(Serializable rdate) {
this.rdate = rdate;
}}
//Posts.hbm.xml
<hibernate-mapping>
<class name="com.guet.bean.Posts" table="posts" schema="dbo" catalog="JavaSystem">
<id name="pid" type="int">
<column name="pid" />
<generator class="assigned" />
</id>
<property name="ptitle" type="string">
<column name="ptitle" />
</property>
<property name="pauther" type="string">
<column name="pauther" length="20" />
</property>
<property name="pdate" type="serializable">
<column name="pdate" />
</property>
<set name="replyses" table="replys" inverse="true" lazy="true" fetch="select">
<key>
<column name="pid" />
</key>
<one-to-many class="com.guet.bean.Replys" />
</set>
</class>
</hibernate-mapping>//Replys.hbm.xml
<hibernate-mapping>
<class name="com.guet.bean.Replys" table="replys" schema="dbo" catalog="JavaSystem">
<id name="replyid" type="int">
<column name="replyid" />
<generator class="assigned" />
</id>
<many-to-one name="posts" class="com.guet.bean.Posts" fetch="select">
<column name="pid" />
</many-to-one>
<property name="rcont" type="string">
<column name="rcont" />
</property>
<property name="rauther" type="string">
<column name="rauther" length="10" />
</property>
<property name="rdate" type="serializable">
<column name="rdate" />
</property>
</class>
</hibernate-mapping>
replys表的pid为posts表pid的外键