0

I have a field defined like this

@MappedSupperclass
public abstract class BaseItem {

    ...
    @Lob @Basic(fetch=FetchType.EAGER)
    private String description;
    ...
}

@Entity
public class Item extends BaseItem {
}

I'm using MySQL 5 and the desccription field type is TEXT.

While trying to read an object of type Item I get the following error:

java.io.StreamCorruptedException: invalid stream header: 6576656E
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at org.datanucleus.store.rdbms.datatype.BlobImpl.getObject(BlobImpl.java:121)
    at org.datanucleus.store.rdbms.mapping.AbstractLargeBinaryRDBMSMapping.getObjectForBytes(AbstractLargeBinaryRDBMSMapping.java:362)
    at org.datanucleus.store.rdbms.mapping.AbstractLargeBinaryRDBMSMapping.getObject(AbstractLargeBinaryRDBMSMapping.java:395)
    at org.datanucleus.store.mapped.mapping.AbstractContainerMapping.getObject(AbstractContainerMapping.java:228)
    at org.datanucleus.store.rdbms.fieldmanager.ResultSetGetter.fetchObjectField(ResultSetGetter.java:176)
    at org.datanucleus.state.AbstractStateManager.replacingObjectField(AbstractStateManager.java:2353)
    ...

Do you have any idea of what are the possible causes for this?

I'm using JDK6 and DataNucleus 3.1.1.

Adrian Ber
  • 20,474
  • 12
  • 67
  • 117
  • This seems to be a provider specific bug. DataNucleus uses the term feature but their handling of @Lob annotated fields doesn't seem JPA compliant to me. If you are stuck with them as a JPA provider then you will have to remove that annotation. – Perception Dec 23 '12 at 02:02
  • @Perception, if you have some issue the "correct" way of reporting it is to raise an issue in public JIRA with testcase that demonstrates it (rather than third party site "complaints"). JPA compliance is governed by a TCK (as complete as it is), and that passes. Retrieval of data obviously depends on how the data is stored in that column (which the OP doesn't define here), so whether it is serialised is crucial to any understanding, and its handling (as well as the software version being used of course, again not stated here). – DataNucleus Dec 23 '12 at 10:56
  • @DataNucleus - I myself do not this problem (we are using Hibernate JPA provider). However, the code @AdrianBer posted seems to indicate a DataNucleus issue with the way `@Lob @Basic` fields are handled. Perhaps ask him to file a bug report? – Perception Dec 23 '12 at 12:47
  • @DataNucleus I modified my post and included the version used. The column type is TEXT and the data contains just plain text. – Adrian Ber Dec 23 '12 at 13:02
  • 1
    @Adrian Ber, I tried your case on current DataNucleus codebase (only thing I have available here) and it maps the "description" field to a ClobRDBMSMapping) and consequently reads in plain text values no problem. Look in the log for what is being used in your case (I'd guess at BlobRDBMSMapping but the log tells you). Maybe that was a bug in a previous version, but the only way you can tell that is by trying latest. The log entry you ought to look for is something like _Field ... -> Column(s) ... using mapping of type {...} (org.datanucleus.store.rdbms.mapping.datastore.ClobRDBMSMapping)_ – DataNucleus Dec 23 '12 at 16:09
  • @Perception yes I know who has the issue, but then I was responding to your comments "DataNucleus uses the term feature" and "If you are stuck with them". I'm not aware of any issue being reported on this so such comments seem odd. S.O is about answering people's questions, ... and nothing more – DataNucleus Dec 23 '12 at 16:28

1 Answers1

2

Removing the @Lob annotation fixed the issue.

Adrian Ber
  • 20,474
  • 12
  • 67
  • 117