Hello,
I've just upgraded our software hibernate 3.6.2 from 3.5.5. The update went smoothly until I ran the tests and had this error.
Code:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character
at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.unwrap(CharacterTypeDescriptor.java:34)
at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:52)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)
at org.hibernate.loader.Loader.doQuery(Loader.java:801)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
That got me investigating, and I found that this was my problem :
Code:
@DiscriminatorColumn( discriminatorType = DiscriminatorType.CHAR )
@DiscriminatorValue( DiscriminatorValues.ABSTRACT )
Where, DiscriminatorValues.ABSTRACT is a string constant of length 1.
Now has a work around, I tried @DiscriminatorColumn( discriminatorType = DiscriminatorType.STRING, length = 1 ) and everything went well and worked fine.
Just to test things out, I decided to put the discriminatorType as an Integer, and a new ClassCastException happened.
What I'm currently wondering is if this is a real bug, or a wanted effect?
I know I could leave @DiscriminatorColumn( discriminatorType = DiscriminatorType.STRING, length = 1 ), and be done with it. But, this also triggers a change in MySQL from the DTYPE column to be a varchar(1) instead of a char.
Any pointers at if this is a bug would be greatly appreciated.
Thanks