java.lang.IllegalArgumentException: object is not an instance of declaring class

Hibernate JIRA | Luca Dall'Olio | 8 years ago
  1. 0

    I have a "Master" Entity with a bidirectional (Many-To-One) relationship with a "Detail" Entity. "Detail" has a unidirectional relationship (One-To-Many) to a "Color" Entity Here is the relevant mapping from the Master point of view, using a Map : @javax.persistence.OneToMany(cascade = {javax.persistence.CascadeType.ALL} ,mappedBy = "master") @javax.persistence.MapKey(name = "color") public java.util.Map<java.lang.Long, Detail> getDetails() { return this.details; } The map key is on the "color" relationship (this should not be a MapKeyManyToMany since no additional column is needed on Master). Map key type is a java.lang.Long because of the Color identifier idColor. After a (successful) create of these relationships, when a "merge" operation is called over Master, the following exception is thrown : 18:10:53,403 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: Color, getter method of property: idColor 18:10:53,427 java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112) at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166) at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77) at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240) at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210) at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84) at $Proxy209.update(Unknown Source) ... 57 more Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145) at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183) at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3596) at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3312) at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181) at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218) at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397) at org.hibernate.type.EntityType.replace(EntityType.java:253) at org.hibernate.type.MapType.replaceElements(MapType.java:73) at org.hibernate.type.CollectionType.replace(CollectionType.java:552) at org.hibernate.type.TypeFactory.replace(TypeFactory.java:482) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:340) at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:153) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669) at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245) at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268) at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216) at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169) at org.hibernate.engine.Cascade.cascade(Cascade.java:130) at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:407) at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:152) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227) at org.jboss.ejb3.entity.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:188) ... 91 more I have tried to follow the code at runtime, it looks like the Color identifier idColor is correctly recognized, but at a given point the java.lang.Long is treated like an Entity and the exception comes from the invoking getIdentifier() over the java.lang.Long instance! Here, in my opinion, could be the wrong line in org.hibernate.type.MapType.replaceElements(...) : Object key = cp.getIndexType().replace( me.getKey(), null, session, owner, copyCache ); me.getKey() passes the java.lang.Long identifier to the CollectionPersister, which treats it like an Entity causing the exception.

    Hibernate JIRA | 8 years ago | Luca Dall'Olio
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  2. 0

    WebappMetricsFilter : IllegalArgumentException: object is not an instance of declaring class

    GitHub | 4 years ago | udgupta
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  3. 0

    Spring+JPA+DAO+Tomcat

    Stack Overflow | 5 years ago | Ivan
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    What Jersey doesn't like in my Stateless Session Bean?

    Stack Overflow | 6 years ago | yegor256
    java.lang.IllegalArgumentException: object is not an instance of declaring class
  6. 0

    java.lang.illegalArgumentException when calling pumpEvents using reflection

    Stack Overflow | 5 years ago | GPAshka
    java.lang.RuntimeException: java.lang.IllegalArgumentException: object is not an instance of declaring class

  1. Aria Pahlavan 16 times, last 2 weeks ago
  2. kjhdofjosvs 2 times, last 1 month ago
  3. tyson925 2 times, last 1 month ago
  4. kuldeep 2 times, last 2 months ago
  5. aldrinleal 1 times, last 5 months ago
6 more registered users
72 unregistered visitors
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.IllegalArgumentException

    object is not an instance of declaring class

    at sun.reflect.NativeMethodAccessorImpl.invoke0()
  2. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:597)
    4 frames
  3. Hibernate
    TypeFactory.replace
    1. org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
    2. org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
    3. org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3596)
    4. org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3312)
    5. org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
    6. org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
    7. org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
    8. org.hibernate.type.EntityType.replace(EntityType.java:253)
    9. org.hibernate.type.MapType.replaceElements(MapType.java:73)
    10. org.hibernate.type.CollectionType.replace(CollectionType.java:552)
    11. org.hibernate.type.TypeFactory.replace(TypeFactory.java:482)
    11 frames
  4. Hibernate
    SessionImpl.merge
    1. org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:340)
    2. org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:153)
    3. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126)
    4. org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
    5. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
    5 frames
  5. Hibernate
    Cascade.cascade
    1. org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
    2. org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
    3. org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
    4. org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
    5. org.hibernate.engine.Cascade.cascade(Cascade.java:130)
    5 frames
  6. Hibernate
    SessionImpl.merge
    1. org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:407)
    2. org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:152)
    3. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:126)
    4. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
    5. org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
    6. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
    7. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
    7 frames
  7. Hibernate EJB
    AbstractEntityManagerImpl.merge
    1. org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
    1 frame
  8. org.jboss.ejb3
    TransactionScopedEntityManager.merge
    1. org.jboss.ejb3.entity.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:188)
    1 frame
  9. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    4. java.lang.reflect.Method.invoke(Method.java:597)
    4 frames
  10. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
    1 frame
  11. org.jboss.ejb3
    EJB3InterceptorsInterceptor.invoke
    1. org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
    2. org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    2 frames
  12. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  13. org.jboss.ejb3
    TransactionScopedEntityManagerInterceptor.invoke
    1. org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    1 frame
  14. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  15. org.jboss.ejb3
    AllowedOperationsInterceptor.invoke
    1. org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    1 frame
  16. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  17. org.jboss.aspects
    TxInterceptor$Required.invoke
    1. org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
    2. org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
    2 frames
  18. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  19. org.jboss.aspects
    TxPropagationInterceptor.invoke
    1. org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
    1 frame
  20. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  21. org.jboss.ejb3
    StatelessInstanceInterceptor.invoke
    1. org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    1 frame
  22. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  23. org.jboss.aspects
    RoleBasedAuthorizationInterceptor.invoke
    1. org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
    1 frame
  24. org.jboss.ejb3
    RoleBasedAuthorizationInterceptor.invoke
    1. org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
    1 frame
  25. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  26. org.jboss.aspects
    AuthenticationInterceptor.invoke
    1. org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    1 frame
  27. org.jboss.ejb3
    Ejb3AuthenticationInterceptor.invoke
    1. org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
    1 frame
  28. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  29. org.jboss.ejb3
    ENCPropagationInterceptor.invoke
    1. org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    1 frame
  30. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  31. org.jboss.ejb3
    AsynchronousInterceptor.invoke
    1. org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    1 frame
  32. org.jboss.aop
    MethodInvocation.invokeNext
    1. org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    1 frame
  33. org.jboss.ejb3
    StatelessLocalProxy.invoke
    1. org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
    2. org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
    3. org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
    3 frames
  34. Unknown
    $Proxy209.update
    1. $Proxy209.update(Unknown Source)
    1 frame