java.lang.ClassCastException: java.lang.String

Hibernate JIRA | Pete Geraghty | 9 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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.

    Hibernate JIRA | 9 years ago | Pete Geraghty
    java.lang.ClassCastException: java.lang.String
  2. 0

    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.

    Hibernate JIRA | 9 years ago | Pete Geraghty
    java.lang.ClassCastException: java.lang.String

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.lang.String

      at org.hibernate.type.ComponentType.toLoggableString()
    2. Hibernate
      QueryParameters.traceParameters
      1. org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:377)
      2. org.hibernate.pretty.Printer.toString(Printer.java:76)
      3. org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:277)
      3 frames
    3. Hibernate
      QueryImpl.iterate
      1. org.hibernate.engine.query.HQLQueryPlan.performIterate(HQLQueryPlan.java:210)
      2. org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1192)
      3. org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:46)
      3 frames
    4. hib.example
      EntityWithEmbeddable.main
      1. hib.example.EntityWithEmbeddable.main(EntityWithEmbeddable.java:44)
      1 frame