Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.5
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openehr.rm.datatypes.basic.DataValue" abstract="true" discriminator-value="DataValue" table="data_value">
<id type="long" unsaved-value="0" column="_id" name="_id">
<generator class="identity"/>
</id>
<discriminator/>
<subclass name="org.openehr.rm.datatypes.quantity.datetime.DvWorldDateTime" abstract="true" discriminator-value="DvWorldDateTime">
<property name="dateTime" column="datetime" type="org.joda.time.DateTime" />
<subclass name="org.openehr.rm.datatypes.quantity.datetime.DvDateTime" discriminator-value="dv_datetime">
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
dv = new DvDateTime("2004-10-12T09:01:02");
(dvDateTime makes a joda.Time from this constructor, with getter and setter to joda.DateTime
I use the springframe dao-construction, call dao.save(dv)
Then I want a list of all dv objects, and delete them, this is not elegant, but maybe not my question, so leave that be for the moment, only if it is related to my question, discuss it.
getHibernateTemplate().deleteAll(getHibernateTemplate().find("from org.openehr.rm.datatypes.quantity.datetime.DvDateTime"));
The problem comes when it is trying to retrieve a list of all saved DV's and tries to serialize them. I will need this list more, so that is the question about. The error (excpetion happens in the hibernate-code, not in my own code.
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:234)
at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
at org.hibernate.type.SerializableType.get(SerializableType.java:39)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:826)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:817)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:809)
at zorggemak.dao.orm.openehr.rm.datatypes.quantity.datetime.DvDateTimeDaoImpl.removeAll(DvDateTimeDaoImpl.java:29)
at zorggemak.dao.orm.openehr.rm.datatypes.quantity.datetime.DvDateTimeDaoTest.testSave(DvDateTimeDaoTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.io.StreamCorruptedException: unexpected EOF while reading block data header
at java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.refill(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.read(Unknown Source)
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readUnsignedShort(Unknown Source)
at java.io.ObjectInputStream$BlockDataInputStream.readUTF(Unknown Source)
at java.io.ObjectInputStream.readUTF(Unknown Source)
at org.joda.time.DateTimeZone$Stub.readObject(DateTimeZone.java:943)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.joda.time.chrono.ISOChronology$Stub.readObject(ISOChronology.java:210)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:204)
... 43 more
Name and version of the database you are using:
MySQL 5
The generated SQL (show_sql=true):
I have some debug log around it because it gives very clear where the error occurs
Saving the object
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.quantity.datetime.DvDateTime
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.quantity.datetime.DvDateTime
DEBUG [main] (SerializationHelper.java:141) - Starting serialization of object [2004-10-12T09:01:02.000+02:00]
DEBUG [main] (SerializationHelper.java:198) - Starting deserialization of object
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.DateTime]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.base.BaseDateTime]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.chrono.ISOChronology$Stub]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.DateTimeZone$Stub]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (BasicEntityPersister.java:1732) - Inserting entity: org.openehr.rm.datatypes.quantity.datetime.DvDateTime (native id)
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (ConnectionManager.java:296) - opening JDBC connection
DEBUG [main] (AbstractBatcher.java:324) - insert into data_value (normal_range_id, accuracyPercent, accuracy, magnitudeStatus, units, datetime, value, class) values (?, ?, ?, ?, ?, ?, ?, 'dv_datetime')
Hibernate: insert into data_value (normal_range_id, accuracyPercent, accuracy, magnitudeStatus, units, datetime, value, class) values (?, ?, ?, ?, ?, ?, ?, 'dv_datetime')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.datatypes.quantity.datetime.DvDateTime#<null>]
DEBUG [main] (NullableType.java:52) - binding null to parameter: 1
DEBUG [main] (NullableType.java:59) - binding 'false' to parameter: 2
DEBUG [main] (NullableType.java:59) - binding '0.0' to parameter: 3
DEBUG [main] (NullableType.java:52) - binding null to parameter: 4
DEBUG [main] (NullableType.java:59) - binding 's' to parameter: 5
DEBUG [main] (SerializationHelper.java:141) - Starting serialization of object [2004-10-12T09:01:02.000+02:00]
DEBUG [main] (NullableType.java:59) - binding '2c6d8085f3f28096eff2e7aeeaefe4e1aef4e9ede5aec4e1f4e5d4e9ede538bcf8e4eadb5d79828080f8f2809feff2e7aeeaefe4e1aef4e9ede5aee2e1f3e5aec2e1f3e5c4e1f4e5d4e9ede57f7f7961cfddae23828082ca8087e9cde9ecece9f3cc808be9c3e8f2efeeefecefe7f9f4809acceff2e7afeaefe4e1aff4e9ede5afc3e8f2efeeefecefe7f9bbf8f08080807f0b701b30f3f280a7eff2e7aeeaefe4e1aef4e9ede5aee3e8f2efeeefaec9d3cfc3e8f2efeeefecefe7f9a4d3f4f5e2294891e6f1b7d0a7838080f8f0f3f2809feff2e7aeeaefe4e1aef4e9ede5aec4e1f4e5d4e9ede5daefeee5a4d3f4f5e226af811afcb29a63838080f8f0f78f808dc5f5f2eff0e5afc2e5f2ece9eef8f8' to parameter: 6
DEBUG [main] (SerializationHelper.java:141) - Starting serialization of object [2004-10-12T09:01:02.000+02:00]
DEBUG [main] (NullableType.java:59) - binding '2004-10-12T09:01:02' to parameter: 7
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 276
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.quantity.datetime.DvDateTime
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.quantity.datetime.DvDateTime
DEBUG [main] (HibernateAccessor.java:393) - Eagerly flushing Hibernate session
Retrieving the object
DEBUG [main] (QueryTranslatorImpl.java:177) - HQL: from org.openehr.rm.datatypes.quantity.datetime.DvDateTime
DEBUG [main] (QueryTranslatorImpl.java:178) - SQL: select dvdatetime0_._id as column1_, dvdatetime0_.normal_range_id as normal23_5_, dvdatetime0_.accuracyPercent as accurac25_5_, dvdatetime0_.accuracy as accuracy5_, dvdatetime0_.magnitudeStatus as magnitu27_5_, dvdatetime0_.units as units5_, dvdatetime0_.datetime as datetime5_, dvdatetime0_.value as value5_ from data_value dvdatetime0_ where dvdatetime0_.class='dv_datetime'
DEBUG [main] (ErrorCounter.java:72) - throwQueryException() : no errors
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (ConnectionManager.java:296) - opening JDBC connection
DEBUG [main] (AbstractBatcher.java:324) - select dvdatetime0_._id as column1_, dvdatetime0_.normal_range_id as normal23_5_, dvdatetime0_.accuracyPercent as accurac25_5_, dvdatetime0_.accuracy as accuracy5_, dvdatetime0_.magnitudeStatus as magnitu27_5_, dvdatetime0_.units as units5_, dvdatetime0_.datetime as datetime5_, dvdatetime0_.value as value5_ from data_value dvdatetime0_ where dvdatetime0_.class='dv_datetime'
Hibernate: select dvdatetime0_._id as column1_, dvdatetime0_.normal_range_id as normal23_5_, dvdatetime0_.accuracyPercent as accurac25_5_, dvdatetime0_.accuracy as accuracy5_, dvdatetime0_.magnitudeStatus as magnitu27_5_, dvdatetime0_.units as units5_, dvdatetime0_.datetime as datetime5_, dvdatetime0_.value as value5_ from data_value dvdatetime0_ where dvdatetime0_.class='dv_datetime'
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (AbstractBatcher.java:306) - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG [main] (Loader.java:405) - processing result set
DEBUG [main] (Loader.java:410) - result set row: 0
DEBUG [main] (NullableType.java:86) - returning '253' as column: column1_
DEBUG [main] (Loader.java:828) - result row: EntityKey[org.openehr.rm.datatypes.quantity.datetime.DvDateTime#253]
DEBUG [main] (Loader.java:978) - Initializing object from ResultSet: [org.openehr.rm.datatypes.quantity.datetime.DvDateTime#253]
DEBUG [main] (BasicEntityPersister.java:1651) - Hydrating entity: [org.openehr.rm.datatypes.quantity.datetime.DvDateTime#253]
DEBUG [main] (NullableType.java:80) - returning null as column: normal23_5_
DEBUG [main] (NullableType.java:86) - returning 'false' as column: accurac25_5_
DEBUG [main] (NullableType.java:86) - returning '0.0' as column: accuracy5_
DEBUG [main] (NullableType.java:80) - returning null as column: magnitu27_5_
DEBUG [main] (NullableType.java:86) - returning 's' as column: units5_
DEBUG [main] (SerializationHelper.java:198) - Starting deserialization of object
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.DateTime]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.base.BaseDateTime]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.chrono.ISOChronology$Stub]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (SerializationHelper.java:253) - Attempting to locate class [org.joda.time.DateTimeZone$Stub]
DEBUG [main] (SerializationHelper.java:258) - Class resolved through context class loader
DEBUG [main] (AbstractBatcher.java:313) - about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
DEBUG [main] (JDBCContext.java:322) - after autocommit
DEBUG [main] (SessionImpl.java:403) - after transaction completion
DEBUG [main] (SessionFactoryUtils.java:785) - Closing Hibernate Session
DEBUG [main] (SessionImpl.java:269) - closing session
DEBUG [main] (ConnectionManager.java:317) - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG [main] (JDBCContext.java:283) - after transaction completion
DEBUG [main] (SessionImpl.java:403) - after transaction completion
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.406 sec <<< FAILURE!
Debug level Hibernate log excerpt: