Menu

#12 ClassCastException on ListHelper.getAddressSize(Class)

0.9.*
open
Pino
bugs (12)
7
2008-10-02
2008-10-02
No

ClassCastException occurs invoking ListHelper.getAddressSize(Class classType).
The ClassCastException occurs at the instruction:

Entity entity = (Entity)iter.next();

This because the getEntries method on List class returns a Set of Entry instead of a Set of object of the class specified by classType

Discussion

  • Pino

    Pino - 2008-10-03

    Hello,
    The problem is that the CGLIB proxy class is a direct descendent of the type of the one end of the many-to-one relationship so you will not be able to cast to the subtype while the object is being proxied.
    However yuo can invoke Helper methods on a concrete subclass of Entry after finding it by its id.

    The neatest solution to this is to employ the visitor pattern. This will keep code free of hibernate clutter and will also allow you to continue to use lazy loading.
    It will come early.

     
  • Gaetano Perrone

    Gaetano Perrone - 2008-10-03

    Have to rexecute the findByKey for a collection i had just queried form the db
    it's a very big limit. Helper doesn't help me....but need my help...
    :-)
    It's not required to use the visitor pattern,
    there are very slowly simple solutions...for the problem.

    Consider the previous Helper version works perfectly with the proxyied class...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.