d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > A Class To Access My Database In Java > Reward 200 Fg
Prev123
Add Reply New Topic New Poll
Member
Posts: 4,478
Joined: Feb 10 2010
Gold: 1,806.00
Mar 25 2013 11:33am
When I place some pictures in the picture collumb in the database the program crashes in this line:

Gtspiller dyr = em.find(Gtspiller.class, a+1);

the error message is the following. something about Could not deserialize object from byte array.
anyone have any iea what that means?

Code


Exception Description: Could not deserialize object from byte array.
Internal Exception: java.io.StreamCorruptedException: invalid stream header: 47494638
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[billede-->GTSPILLER.BILLEDE]
Descriptor: RelationalDescriptor(holdem.Gtspiller --> [DatabaseTable(GTSPILLER)])
Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [EclipseLink-66] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Could not deserialize object from byte array.
Internal Exception: java.io.StreamCorruptedException: invalid stream header: 47494638
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[billede-->GTSPILLER.BILLEDE]
Descriptor: RelationalDescriptor(holdem.Gtspiller --> [DatabaseTable(GTSPILLER)])
at org.eclipse.persistence.exceptions.DescriptorException.notDeserializable(DescriptorException.java:1218)
at org.eclipse.persistence.mappings.converters.SerializedObjectConverter.convertDataValueToObjectValue(SerializedObjectConverter.java:72)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.getAttributeValue(AbstractDirectMapping.java:699)
at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.valueFromRow(AbstractDirectMapping.java:1299)
at org.eclipse.persistence.mappings.DatabaseMapping.readFromRowIntoObject(DatabaseMapping.java:1326)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoObject(ObjectBuilder.java:445)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:798)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneNormally(ObjectBuilder.java:715)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:668)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:601)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:560)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:717)
at org.eclipse.persistence.queries.ReadObjectQuery.registerResultInUnitOfWork(ReadObjectQuery.java:778)
at org.eclipse.persistence.queries.ReadObjectQuery.executeObjectLevelReadQuery(ReadObjectQuery.java:457)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1081)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040)
at org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:418)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1128)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2871)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1516)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1498)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1449)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.executeQuery(EntityManagerImpl.java:820)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.findInternal(EntityManagerImpl.java:760)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:653)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.find(EntityManagerImpl.java:532)

Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Mar 25 2013 06:14pm
You should encode your images as Strings before you put them in the database, then decode them when you want to use them. I think that might be the problem.

http://javarevisited.blogspot.ca/2012/02/how-to-encode-decode-string-in-java.html

Check out this blog post, it explains how to encode / decode in base64.

Also, i'm not sure, but you might have to download the source code for Base64. You can find tons of them on google. I'd send you one but i'm on my home pc and mine is on my work computer.

I'll send you an example tomorrow if you're still having problems.

This post was edited by labatymo on Mar 25 2013 06:16pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 25 2013 06:17pm
Quote (labatymo @ Mar 25 2013 08:14pm)
You should encode your images as Strings before you put them in the database, then decode them when you want to use them. I think that might be the problem.

http://javarevisited.blogspot.ca/2012/02/how-to-encode-decode-string-in-java.html

Check out this blog post, it explains how to encode / decode in base64.


you can't just write to a blob and read back the stream? it's always worked fine for me in oracle/postgres via jdbc
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Mar 25 2013 06:24pm
Quote (carteblanche @ Mar 25 2013 08:17pm)
you can't just write to a blob and read back the stream? it's always worked fine for me in oracle/postgres via jdbc


It's still being written to a blob, just as a String and that's the only way I've ever done it.
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll