-->
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.  [ 4 posts ] 
Author Message
 Post subject: EOFException when trying to do a query/deserializing an obje
PostPosted: Thu Jul 06, 2006 12:44 pm 
Newbie

Joined: Fri Nov 11, 2005 6:54 pm
Posts: 7
I'm getting an EOFException when trying to do a query with Hibernate. Here's the root cause in my stack trace:

Caused by: java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
... 125 more


It looks like the problems start in org.hibernate.type.SerializableType.get(ResultSet rs, String name)

In the line that reads "byte[] bytes = (byte[]) Hibernate.BINARY.get(rs, name);", the array returned is of length 1, and contains only the byte [49].

From there, it all goes downhill, as this byte array is passed to the ObjectInputStream, which complains that this isn't a valid object stream, I guess.

Not sure where to go from here. As far as I can tell, the POJO model classes are correct, the mapping XML file is correct, the DB table structure is correct, etc.

Where should I look next?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 2:16 pm 
Newbie

Joined: Fri Nov 11, 2005 6:54 pm
Posts: 7
I got the source code for my SQL driver and dug a bit deeper with the debugger. The query statement given to the SQL driver is:

Code:
com.mysql.jdbc.ServerPreparedStatement[32] - select normalreso0_.id as id11_, normalreso0_.UserId as UserId11_, normalreso0_.deleted as deleted11_, normalreso0_.path as path11_, normalreso0_.type as type11_, normalreso0_.kbAssetTypeId as kbAssetT6_11_, normalreso0_.subProject as subProject11_ from Resource normalreso0_ where normalreso0_.deleted = 0 and normalreso0_.id=179 and normalreso0_.deleted=0


Is this name mangling normal? What it calls "normalreso0_" is actually "normalResource" in the XML mapping file, and "resource" in the DB table.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
   <class name="com.castortech.iris.database.projectrepository.modelobjects.NormalResource" table="Resource" where="deleted = 0">
      <id name="id">
         <generator class="increment" />
      </id>
      <property name="UserId"/>
      <property name="deleted" />
      <property name= "path" />
      <property name="type"/>
      <property name="kbAssetTypeId" />
      <property name="subProjectId" column="subProject"/>
   </class>
</hibernate-mapping>



Code:
CREATE TABLE `resource` (
  `id` int(8) NOT NULL auto_increment,
  `UserId` int(8) default NULL,
  `path` varchar(250) default NULL,
  `deleted` tinyint(1) default NULL,
  `type` int(8) default NULL,
  `KBassetTypeId` int(8) default NULL,
  `subProject` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=180 ;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 2:59 pm 
Newbie

Joined: Fri Nov 11, 2005 6:54 pm
Posts: 7
Nevermind about the name mangling. I didn't see the from Resource normalreso0_.

After a bit more debugging, I see that the ResultSet is correctly populated. I also have an explanation for the 49 in the byte array. 49 is the ASCII code for the character '1', and 1 is the value of type for the resource with id = 179. So for whatever reason, it's taking the value in the type column and converting it to a string, then converting that string to a byte array, and then trying to use the byte array to deserialize into an object. Any idea why this would happen?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 5:50 pm 
Newbie

Joined: Fri Nov 11, 2005 6:54 pm
Posts: 7
Issue is fixed. In the SQL table, I declared "type" to be an int, but in the model object it was an enum. I added a UserType and now all is working.

Any way I can mark my own posts as being helpful? ;)


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

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.