-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException when using DiscriminatorColumn/Value
PostPosted: Wed Mar 23, 2011 2:40 pm 
Newbie

Joined: Wed Mar 23, 2011 2:14 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: ClassCastException when using DiscriminatorColumn/Value
PostPosted: Fri Mar 25, 2011 7:46 am 
Newbie

Joined: Wed Mar 23, 2011 2:14 pm
Posts: 2
So I guess I could try and file a jira for this?


Top
 Profile  
 
 Post subject: Re: ClassCastException when using DiscriminatorColumn/Value
PostPosted: Fri Aug 19, 2011 11:59 am 
Newbie

Joined: Tue Aug 16, 2011 5:58 pm
Posts: 6
jducharme wrote:
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


Did you ever submit your problem? I'm not sure simply seeking out a Jira file is the best first step. The developers should probably take a crack at it. It seems this problem may be unique to you as I have not seen much as far as the mentioned upgrade is concerned. I know that when I tried to fix an issue myself, I ended up spending days on cloud computing experiments just to get everything in safe storage and lined up with the proper IT calibration. It has been a good task for the resume, but if an IT staffing thinks I'm too smart I could be put in a weird place, haha.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.