Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / January 2006

Tip: Looking for answers? Try searching our database.

deserialisation problem

Thread view: 
VisionSet - 30 Jan 2006 11:00 GMT
Fresh compile
clean out the database
objects persisted to database okay
objects retrieved from database okay using the below code.

Then I terminate my java server and client, restart and I get an
EOFException in the below deserialisation.  I understand this is because the
runtime can't find a compatible class definition - but it hasn't changed -
it is running the same code!

I am manually deserialising because I couldn't get autoDeserialize=true to
work in MySQL apparantly because the driver could not see my persisted
objects class on the classpath.  Perhaps I've been lucky with classpath
issues in the past, but I don't know how to make ConnectorJ see my classes -
how do I do this?

private static Game deserializeGame(ResultSet rs) throws SQLException {

 byte[] byteArray = (byte[]) rs.getObject(GameDB.Col.GAME);
 try {
  return (Game) new ObjectInputStream(
   new ByteArrayInputStream(byteArray)).readObject();
 }
 catch (ClassNotFoundException cnfe) {
  throw new RuntimeException(cnfe);
 }
 catch (IOException ioe) {
  throw new RuntimeException(ioe);
 }
}

TIA
--
Mike W
VisionSet - 30 Jan 2006 11:52 GMT
>    return (Game) new ObjectInputStream(
>     new ByteArrayInputStream(byteArray)).readObject();

...and I have closed the read stream properly now,
but it still throws EOFException, but now it seems more sporadic.  When I
restart server it will retrieve objects okay for a while then fall over
seemingly without reason!

--
Mike W
VisionSet - 30 Jan 2006 23:30 GMT
> >    return (Game) new ObjectInputStream(
> >     new ByteArrayInputStream(byteArray)).readObject();
[quoted text clipped - 3 lines]
> restart server it will retrieve objects okay for a
> while then fall over

err like when the object got too big!

> seemingly without reason!

or so it seemed!

Okay, a bit embarrassing but it won't hurt to make this googlable.
MySQL Blob is 2 + 2^16 bytes tops
So if you put more than that in it ceases to represent a Java Object!!
Moral - your used to seeing odd exceptions when things go wrong and get used
to assuming they result from a very confused serialisation mechanism - don't
rule out the obvious - EOF meant just that!!

--
Mike W
Chris Uppal - 31 Jan 2006 11:41 GMT
> MySQL Blob is 2 + 2^16 bytes tops
> So if you put more than that in it ceases to represent a Java Object!!

Surprising that MySQL didn't report errors when you attempted to store a
byte-stream which was longer than the maximum.

Am I misunderstanding you or is MySQL just broken in this respect ?

   -- chris
VisionSet - 31 Jan 2006 15:03 GMT
> > MySQL Blob is 2 + 2^16 bytes tops
> > So if you put more than that in it ceases to represent a Java Object!!
[quoted text clipped - 3 lines]
>
> Am I misunderstanding you or is MySQL just broken in this respect ?

I do a

PreparedStatement.setObject(colNum, myByteArray);

on behalf of an SQL update.

It never throws an SQLException, I only know about it when I manually
deserialise.

Yes it would be nice if it did that, it might give a warning, I don't think
they materialise as SQLExceptions, there probably is some API I can use to
check warnings, but I don't.

--
Mike W


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.