-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: ClassCastException when accessing a getter [SOLVED]
PostPosted: Fri Jan 31, 2014 5:40 am 
Newbie

Joined: Mon Jul 19, 2010 7:21 am
Posts: 5
Hibernate 3.5.6 + Spring 3.0.5
JDK 7
Oracle 11g

I am seeing intermittent problems with my application that has been running for many months without issue.

The error presents itself as:
Code:
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.myapp.app.domain.User.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.myapp.app.domain.User.id
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy29.updateEvent(Unknown Source)
   at com.myapp.app.jobs.EventProcessingJob.doInSession(EventProcessingJob.java:95)
   at com.myapp.app.jobs.OpenSessionInViewJob.doExecute(OpenSessionInViewJob.java:47)
   at com.myapp.app.jobs.AbstractSpringEnabledJob.execute(AbstractSpringEnabledJob.java:24)
   at org.quartz.core.JobRunShell.run(JobRunShell.java:216)
   ... 1 more
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.myapp.User.id
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:198)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3852)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3560)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:204)
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:449)
   at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:280)
   at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:290)
   at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:668)
   at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3380)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
   at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
   ... 14 more
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@4a997131
   at sun.reflect.GeneratedMethodAccessor377.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:172)
   ... 34 more


My hibernate mappings are:

Code:
Event.hbm.xml:

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">

   <class name="com.myapp.app.domain.event.Event" table="EVENTS" discriminator-value="0">
      
      <id name="id" column="EVENT_ID" type="java.lang.Integer">           
            <generator class="native"/>           
        </id>
        <discriminator column="EVENT_TYPE" type="int"/>
       
        <property name="eventName" column="EVENT_NAME" not-null="true" unique="true"/>

      <property name="lastFiredDateTime" column="LAST_FIRED_DATE_TIME" not-null="false"/>
       
      ...
      ...
      
        <many-to-one name="owner" class="com.myapp.app.domain.User" column="OWNER" lazy="no-proxy"/>
       
        <subclass name="com.myapp.app.domain.event.DatabaseEvent" discriminator-value="3">
            <property name="queries" column="QUERY"/>
        </subclass>
        <subclass name="com.myapp.app.domain.event.FileEvent" discriminator-value="2">
            <property name="fileName" column="FILE_NAME"/>
        </subclass>
        <subclass name="com.myapp.app.domain.event.ManualEvent" discriminator-value="4">
        </subclass>
    </class>
</hibernate-mapping>

User.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">

   <class name="com.myapp.app.domain.User" table="USER">
      
      <id name="id" column="USER_ID" type="java.lang.Integer">           
         <generator class="native"/>           
        </id>
       
        <property name="name" column="NAME" not-null="true" unique="true"/>

      ...
      ... More columns mapped....
       
    </class>
       
</hibernate-mapping>


The error occurs when updating the Event record during background activities to set the lastFiredTime field (part of a scheduled Quartz job). We can have up to 20 activities happening in parallel (but they all run for varying amounts of time) and the User may be the same user for jobs.

The intermittent nature of this is really confusing me, the number of failures each day varies as is which of them fail. Can anyone shed some light?


Last edited by johnmcteague on Fri Jan 31, 2014 8:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Intermittent ClassCastException when accessing a getter
PostPosted: Fri Jan 31, 2014 7:13 am 
Newbie

Joined: Mon Jul 19, 2010 7:21 am
Posts: 5
Turns out this is related to JDK7. Rolling back to JDK 6 seems to fix it. This may only be an issue when we have multiple jobs using the same user.

I will post back further details if I get to the bottom of why.


Top
 Profile  
 
 Post subject: Re: Intermittent ClassCastException when accessing a getter
PostPosted: Fri Jan 31, 2014 8:12 am 
Newbie

Joined: Mon Jul 19, 2010 7:21 am
Posts: 5
See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7023180

JDK 7 changed Method.getDeclaredMethods() so the order is not guaranteed.

If you have a mapped class with Object getProperty and boolean isProperty (yeah, I know that may be weird, but I had it in my code) then with every restart of your app BasicPropertyAccessor.getterMethod(...) may find the isProperty rather than the getproperty method and cause issues in your app.

Needless to say I am going to rename my is... method.

Hope this helps someone else in the future.


Top
 Profile  
 
 Post subject: Re: ClassCastException when accessing a getter [SOLVED]
PostPosted: Fri Jan 31, 2014 4:20 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
could you verify this problem doesn't happen with a more recent version of Hibernate ORM please?
Ideally I'd need to know about 4.2.8.Final, but I guess you might need to upgrade Spring for that move

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.