java.lang.IllegalStateException: Problem translating field private com.google.appengine.api.datastore.Blob com.bookletona.users.User.image

Google Groups | ghost23 | 5 years ago
  1. 0

    twig 1.0.4 - problem with loading blob

    Google Groups | 5 years ago | ghost23
    java.lang.IllegalStateException: Problem translating field private com.google.appengine.api.datastore.Blob com.bookletona.users.User.image
  2. 0

    When I set a query paramter on a TypedQuery that is a primitive array (in my case byte[]) there will be a ClassCastException inside the method org.hibernate.ejb.AbstractQueryImpl#registerParameterBinding because the method tries to cast byte[] to Object[]: {noformat} ... else if (value.getClass().isArray()) { final Object[] array = (Object[]) value; ... {noformat} *Produces:* {noformat} java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object; at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:348) at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:359) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310) {noformat} *Reproduction is easy:* {noformat} em.createQuery("SELECT e.stringValue FROM entity e WHERE e.guid = :guid", String.class).setParameter("guid", new byte[16]); {noformat} having entity defined as: {noformat} @Entity(name = "entity") public class Entity { @Column(length=16) byte[] guid; @Column String stringValue; } {noformat} *Solution:* The solution to the problem is quite simple. By checking list types only if the direct type match doesn't return true, the system doesn't have such an issue. The following patch fixes the bug: Patch for the method inside org.hibernate.ejb.AbstractQueryImpl.java[274]: {noformat} protected void registerParameterBinding(Parameter parameter, Object value) { final Class<?> targetType = parameter.getParameterType(); if ( value != null && targetType != null ) { if (!targetType.isInstance(value)) { if ( Collection.class.isInstance( value ) ) { final Collection collection = (Collection) value; // validate the elements... for ( Object element : collection ) { if ( ! targetType.isInstance( element ) ) { throw new IllegalArgumentException( "Parameter value [" + element + "] was not matching type [" + targetType.getName() + "]" ); } } } else if ( value.getClass().isArray() ) { final Object[] array = (Object[]) value; for ( Object element : array ) { if ( ! targetType.isInstance( element ) ) { throw new IllegalArgumentException( "Parameter value [" + element + "] was not matching type [" + targetType.getName() + "]" ); } } } else { throw new IllegalArgumentException( "Parameter value [" + value + "] was not matching type [" + targetType.getName() + "]" ); } } } if ( parameterBindings == null ) { parameterBindings = new HashMap(); } parameterBindings.put( parameter, value ); } {noformat}

    Hibernate JIRA | 7 years ago | J├╝rgen Kellerer
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
  3. 0

    CLI console throws ClassCastException when method returns byte array

    https://bugzilla.redhat.com/bugzilla/ | 5 years ago | John Sanda
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    cxf-user - java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object

    nabble.com | 3 weeks ago
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
  6. 0

    primitive arrays cause ClassCastException in eclipse 6.8.1 plugin

    GitHub | 4 years ago | willkil
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;

    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

      [B cannot be cast to [Ljava.lang.Object;

      at com.vercer.engine.persist.conversion.CollectionConverter.createCollectionInstance()
    2. com.vercer.engine
      ObjectFieldTranslator.activate
      1. com.vercer.engine.persist.conversion.CollectionConverter.createCollectionInstance(CollectionConverter.java:151)
      2. com.vercer.engine.persist.conversion.CollectionConverter.convert(CollectionConverter.java:111)
      3. com.vercer.engine.persist.conversion.CombinedTypeConverter.convert(CombinedTypeConverter.java:37)
      4. com.vercer.engine.persist.conversion.DefaultTypeConverter.convert(DefaultTypeConverter.java:56)
      5. com.vercer.engine.persist.translator.ObjectFieldTranslator.activate(ObjectFieldTranslator.java:127)
      6. com.vercer.engine.persist.standard.StrategyObjectDatastore$2.activate(StrategyObjectDatastore.java:222)
      7. com.vercer.engine.persist.translator.ObjectFieldTranslator.propertiesToTypesafe(ObjectFieldTranslator.java:56)
      8. com.vercer.engine.persist.translator.ListTranslator.propertiesToTypesafe(ListTranslator.java:48)
      9. com.vercer.engine.persist.translator.ObjectFieldTranslator.activate(ObjectFieldTranslator.java:106)
      9 frames