[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3148?page=c...
]
Ash Lux commented on HHH-3148:
------------------------------
Using 3.2.4 sp1 here.
I was getting the ClassCastException when using property-ref in a set. I got one
stacktrace leading back to this code with debugging and another stacktrace with logging
turned off.
Changing ComponentType to use String.valueOf(value) instead of throwing an exception
worked for me to see the real exception which was "Caused by: java.sql.SQLException:
ORA-00904: "RUNWAYS0_"."ID": invalid identifier".
ClassCastException was completely misleading.
I could be wrong, but it appears this was added Feb 21, 2005:
http://viewvc.jboss.org/cgi-bin/viewvc.cgi/hibernate/core/tags/v324sp1/sr....
There are multiple issues filed for this particular problem, HHH-2052, for example.
Exception thrown by debug trace code: ComponentType toLoggableString
--------------------------------------------------------------------
Key: HHH-3148
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3148
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6.ga
HibernateAnnotations 3.3.0.ga
Oracle 10g Express Edition
Reporter: Pete Geraghty
Priority: Minor
Attachments: NullableType.java, ToLoggableStringExample.txt
The method toLoggableString in ComponentType is used to provide tracing output when
running with log level DEBUG. In some circumstances it throws a ClassCastException.
This is not a good idea in tracing code and obscures underlying problems.
In my case the underlying problem was a previous incorrect call to set a parameter value
in a query. I saw that previous JIRA issues have mentioned this ClassCastException as a
side effect of other underlying problems - it is a distraction and time-waster.
Lines 375-378 read:
EntityMode entityMode = tuplizerMapping.guessEntityMode( value );
if ( entityMode == null ) {
throw new ClassCastException( value.getClass().getName() );
}
A better solution would be to just us String.valueOf
EntityMode entityMode = tuplizerMapping.guessEntityMode( value );
if ( entityMode == null ) {
return String.valueOf(value);
}
Another possibility would be to concatenate some diagnostic message with String.valueOf,
but personally I don't think that be helpful.
Stack trace is:
Exception in thread "main" java.lang.ClassCastException: java.lang.String
at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:377)
at org.hibernate.pretty.Printer.toString(Printer.java:76)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:277)
at org.hibernate.engine.query.HQLQueryPlan.performIterate(HQLQueryPlan.java:210)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1192)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:46)
at hib.example.EntityWithEmbeddable.main(EntityWithEmbeddable.java:44)
Example code for the classes and schema to reproduce is pasted into the attachment.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira