deserialisation problem

V

VisionSet

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
 
V

VisionSet

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!
 
V

VisionSet

...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

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!!
 
C

Chris Uppal

VisionSet said:
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
 
V

VisionSet

Chris Uppal said:
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 ?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top