net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of mypackage.Product.id

Hibernate JIRA | Jonas Kilian | 1 decade ago
  1. 0

    ...unless log level set to DEBUG. Assume we have 3 entities known by Hibernate: customer, product, address Customer has n products, if I say customer.getProducts().add( address ); // wrong type session.save(customer); Hibernate does not complain but simply does NOT SAVE the entities! Note: for customer.getAccounts().add("wrong account type"); // wrong type session.save(customer); Hibernate says: "No persister for..." - that's why I used the address instance which is known by Hibernate. Now what's really interesting: Hibernate behaves correctly when loglevel for net.sf.hibernate is set to DEBUG, in this case it gives the following exception: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of mypackage.Product.id at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:114) at net.sf.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:306) at net.sf.hibernate.proxy.HibernateProxyHelper.getIdentifier(HibernateProxyHelper.java:48) at net.sf.hibernate.type.EntityType.toString(EntityType.java:84) at net.sf.hibernate.type.PersistentCollectionType.toString(PersistentCollectionType.java:82) at net.sf.hibernate.impl.Printer.toString(Printer.java:49) at net.sf.hibernate.impl.Printer.toString(Printer.java:82) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2270) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228) at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:313) at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:491) at ... 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:585) at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:100) ... 28 more If you go down the trace, you'll see that Printer.toString(Iterator iter) triggers the querying of the ID, this method in turn starts with if ( !log.isDebugEnabled() || !iter.hasNext() ) return; No matter what you do about the typesafety issue, which is probably gone with Generics, Hibernate should behave the same independently from the log level.

    Hibernate JIRA | 1 decade ago | Jonas Kilian
    net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of mypackage.Product.id
  2. 0

    ...unless log level set to DEBUG. Assume we have 3 entities known by Hibernate: customer, product, address Customer has n products, if I say customer.getProducts().add( address ); // wrong type session.save(customer); Hibernate does not complain but simply does NOT SAVE the entities! Note: for customer.getAccounts().add("wrong account type"); // wrong type session.save(customer); Hibernate says: "No persister for..." - that's why I used the address instance which is known by Hibernate. Now what's really interesting: Hibernate behaves correctly when loglevel for net.sf.hibernate is set to DEBUG, in this case it gives the following exception: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of mypackage.Product.id at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:114) at net.sf.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:306) at net.sf.hibernate.proxy.HibernateProxyHelper.getIdentifier(HibernateProxyHelper.java:48) at net.sf.hibernate.type.EntityType.toString(EntityType.java:84) at net.sf.hibernate.type.PersistentCollectionType.toString(PersistentCollectionType.java:82) at net.sf.hibernate.impl.Printer.toString(Printer.java:49) at net.sf.hibernate.impl.Printer.toString(Printer.java:82) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2270) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228) at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:313) at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:491) at ... 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:585) at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:100) ... 28 more If you go down the trace, you'll see that Printer.toString(Iterator iter) triggers the querying of the ID, this method in turn starts with if ( !log.isDebugEnabled() || !iter.hasNext() ) return; No matter what you do about the typesafety issue, which is probably gone with Generics, Hibernate should behave the same independently from the log level.

    Hibernate JIRA | 1 decade ago | Jonas Kilian
    net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of mypackage.Product.id
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Hibernate Community • View topic - junit fails with mysql

    hibernate.org | 8 months ago
    net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.hibernate.test.Jay.id

    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. net.sf.hibernate.PropertyAccessException

      IllegalArgumentException occurred calling getter of mypackage.Product.id

      at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get()
    2. net.sf.hibernate
      SessionImpl.flush
      1. net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:114)
      2. net.sf.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:306)
      3. net.sf.hibernate.proxy.HibernateProxyHelper.getIdentifier(HibernateProxyHelper.java:48)
      4. net.sf.hibernate.type.EntityType.toString(EntityType.java:84)
      5. net.sf.hibernate.type.PersistentCollectionType.toString(PersistentCollectionType.java:82)
      6. net.sf.hibernate.impl.Printer.toString(Printer.java:49)
      7. net.sf.hibernate.impl.Printer.toString(Printer.java:82)
      8. net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2270)
      9. net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228)
      9 frames
    3. Hibernate
      HibernateTemplate.save
      1. org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214)
      2. org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:313)
      3. org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:491)
      3 frames