java.lang.ClassCastException: java.lang.String

Hibernate JIRA | Pete Geraghty | 9 years ago
  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
  3. 0

    Vector and AbstractTableModel

    Oracle Community | 1 decade ago | 843805
    java.lang.ClassCastException: java.lang.String
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    get the row id of an spinner item populated from database

    Stack Overflow | 4 years ago | user1381760
    java.lang.ClassCastException: java.lang.String
  6. 0

    How to upload Byte array (image) on facebook wall with android application?

    Stack Overflow | 4 years ago | TKumar
    java.lang.ClassCastException: java.lang.String

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    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