-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SerializationException: could not deserialize
PostPosted: Mon Jul 18, 2011 2:34 pm 
Newbie

Joined: Thu Jul 14, 2011 11:36 am
Posts: 9
I got the following exception (Hibernate 3.5.6):

org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:262)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:306)
....
Caused by: java.io.StreamCorruptedException: invalid stream header: 35353530
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:328)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:318)
at org.hibernate.util.SerializationHelper.doDeserialize(SerializationHelper.java:237)
...

Code:
@Entity @Table(name="problem")
public class Problem implements Serializable, Cloneable {

    private Set<ProblemScreenMetaproperty> screenMetaproperties = new HashSet<ProblemScreenMetaproperty>();

    @OneToMany(cascade=CascadeType.ALL,orphanRemoval=true,mappedBy="id.problem")
    public Set<ProblemScreenMetaproperty> getScreenMetaproperties() {
        return screenMetaproperties;
    }
    ....
}

@Entity @Table(name="problem_screen_metaproperty")
public class ProblemScreenMetaproperty implements Serializable {
   private ProblemScreenMetapropertyKey id;

   @EmbeddedId
   public ProblemScreenMetapropertyKey getId() {
           return id;
   }
        ...
}

@Embeddable
public class ProblemScreenMetapropertyKey implements Serializable {
   private Problem problem;
   private ScreenMetapropertyDefinition screenMetaproperty;

   public Problem getProblem() {
      return problem;
   }

   public ScreenMetapropertyDefinition getScreenMetaproperty() {
      return screenMetaproperty;
   }
   ....
}


I solved the issue by adding the following annotations to the Composite Key (ProblemScreenMetapropertyKey)

Code:
@Embeddable
public class ProblemScreenMetapropertyKey implements Serializable {
   private Problem problem;
   private ScreenMetapropertyDefinition screenMetaproperty;

   @ManyToOne(fetch=FetchType.EAGER)
   @JoinColumn(name="problem_id", unique=false, nullable=true, insertable=true, updatable=true)
   public Problem getProblem() {
      return problem;
   }

   @ManyToOne(fetch=FetchType.EAGER)
   @JoinColumn(name="screen_metaproperty_id", unique=false, nullable=true, insertable=true, updatable=true)
   public ScreenMetapropertyDefinition getScreenMetaproperty() {
      return screenMetaproperty;
   }
   ....
}


So the issue is solved, but it seems to me that Hibernate may provide a more specific message about the issue to make troubleshooting easier.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.