Saturday, December 3, 2011

ClassCastException with Hibernate: org.hibernate.type.DateType cannot be cast to org.hibernate.type.VersionType

I ran into a weird error when starting a Seam App with JPA (Hibernate) on JBoss

2011-08-03 14:30:17,938 [main] ERROR [org.jboss.deployment.scanner.URLDeploymentScanner] Incomplete Deployment listing:

--- MBeans waiting for other MBeans ---
ObjectName: persistence.units:ear=mainsite.ear,jar=kaptest_domain.jar,unitName=commonDatabase
  State: FAILED
  Reason: java.lang.ClassCastException: org.hibernate.type.DateType cannot be cast to org.hibernate.type.VersionType
  I Depend On:
    jboss.jca:service=DataSourceBinding,name=jdbc.CommonTransactionDS
  Depends On Me:
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=AdobeMeetingDAO_Seam_Impl,service=EJB3
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=AdobeProductDAO_Seam_Impl,service=EJB3
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=AdobeUserDAO_Seam_Impl,service=EJB3
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=AverageRatingServiceImpl,service=EJB3
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=BookstoreProductServiceImpl,service=EJB3
    jboss.j2ee:ear=mainsite.ear,jar=kaptest_domain.jar,name=BookstoreSearchServiceImpl,service=EJB3
...
...
WHAT??? java.lang.ClassCastException: org.hibernate.type.DateType cannot be cast to org.hibernate.type.VersionType

Anyway, for some reason, hibernate reverse engineer puts the @Version annotation to fields called timestamp as it expects it to be of type java.sql.Timestamp
Unfortunatly, my property was of type java.util.Date which is incomaptible with the @Version annotation.
I removed the @Version and it worked!

2 comments:

  1. 2 year old post but it was the solution to the Hibernate error I was trying to puzzle out. Many thanks to you (and Google for taking me here ;-)

    ReplyDelete