Hi-
I'm using Hibernate 2.1.3 and having some wierd behavior when trying to use a version/timestamp for optimistic locking. JDK 1.4, OracleDialect.
I prevoiusly had the column mapped as a simple property, and everything worked fine.
The SQL datatype of the Version column is DATE, and the java type of the version is java.sql.Timestamp.
So my first attempt was to use the <timestamp> element.
<timestamp name="modifiedDate" column="MODIFIED_DATE"/>
This caused the following exception
java.lang.ClassCastException
at net.sf.hibernate.type.TimestampType.deepCopyNotNull(TimestampType.java:55)
at net.sf.hibernate.type.NullableType.deepCopy(NullableType.java:96)
at net.sf.hibernate.type.AbstractType.assemble(AbstractType.java:50)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:54)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:46)
at net.sf.hibernate.impl.SessionImpl.assembleCacheEntry(SessionImpl.java:2123)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2101)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1942)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.assemble(EntityType.java:130)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:54)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:46)
at net.sf.hibernate.impl.SessionImpl.assembleCacheEntry(SessionImpl.java:2123)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2101)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1942)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.assemble(EntityType.java:130)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:54)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:46)
at net.sf.hibernate.impl.SessionImpl.assembleCacheEntry(SessionImpl.java:2123)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2101)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1980)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1909)
at market.media.dao.MediaDAO.findByPrimaryKey(MediaDAO.java:40)
After reading the docs it seemed like the built in type TimestampType could not go from a SQL Date to a java.sql.Timestamp, so I attempted to implement a type that would do that, by cut/paste/editing the code from hibernate TimestampType.
<version name="modifiedDate" type="market.util.TimestampDateType" column="MODIFIED_DATE"/>
At that point I basically got the same kind of class cast exception. So I ran in a debugger with a breakpoint set in the deepCopyNotNull method of my
Type impl.
While inspecting some of the values passed in to deepCopyNotNull, I noticed that while for the most part Timestamps were being passed in.
What was troubling was in a few instances, Strings that were properties of the object, but totally unrelated to the Version were being passed in.
This seems very odd to me. Is this what is supposed to happen?
|