• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Extending a class which itself extends a parameterized generic class

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have the following classes...

A generic DAO class:


A domain DAO class extending the generic DAO class:


A database server specific domain DAO class extending the domain DAO class:


The compile is perfectly happy with the above.

But running the test demo class:


gives the following exception:

Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
at com.thalasoft.learnintouch.core.dao.hibernate.GenericHibernateDao.<init>(GenericHibernateDao.java:41)
at com.thalasoft.learnintouch.core.dao.hibernate.UserHibernateDao.<init>(UserHibernateDao.java:26)
at com.thalasoft.learnintouch.core.dao.h2.hibernate.UserCustomHibernateDao.<init>(UserCustomHibernateDao.java:17)
at com.thalasoft.learnintouch.core.exception.TestDemo.main(TestDemo.java:8)



Any clue ?
 
Sheriff
Posts: 28365
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

at com.thalasoft.learnintouch.core.dao.hibernate.GenericHibernateDao.<init>(GenericHibernateDao.java:41)



There's your clue -- that's the line of code which throws the exception. It's in a constructor of the GenericHibernateDao class, at line 41 specifically. You haven't shown us that code. If you still don't see the problem when you look there, then go ahead and post the code for us to look at.
 
Stephane Eybert
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the comment. Here is the class source code. The line "41" is at line 12 in this post.

 
Stephane Eybert
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved the issue by using the TypeResolver of TypeTools from Jonathan Halterman at https://github.com/jhalterman/typetools

Here is the code chunk I used:


Thanks to you Jonathan !
 
knowledge is the difference between drudgery and strategic action -- tiny ad
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic