This content has been marked as final.
Show 4 replies
-
1. Re: hibernate proxy and typecast
tom.baeyens Dec 4, 2007 8:31 AM (in response to porcherg)another potential solution to this problem is to use polymorfic methods on the object.
i believe that is the only solution that will really work.
for WireContext and Initializable, you could e.g. introduce a method isInitializable on the Descriptor or AbstractDescriptor -
2. Re: hibernate proxy and typecast
porcherg Dec 4, 2007 10:40 AM (in response to porcherg)"tom.baeyens@jboss.com" wrote:
another potential solution to this problem is to use polymorfic methods on the object.
i believe that is the only solution that will really work.
for WireContext and Initializable, you could e.g. introduce a method isInitializable on the Descriptor or AbstractDescriptor
The method isInitializable can be used to check if the object is an instance of Initializable, but the cast still fails.
In the WireContext, there 's a list of pendingInitialization. A pending init has a Initializable.
To remove the cast, we need to change pendingInitialization to use only AbstractDescriptor, and to add an empty "initialize" method in AbstractDescriptor.
With the change, the tests pass. Is this a good way to resolve this issue ?
Guillaume -
3. Re: hibernate proxy and typecast
tom.baeyens Dec 17, 2007 9:31 AM (in response to porcherg)i merged initializable into descriptor.
initializable disappeared and the methods were added to descriptor. -
4. Re: hibernate proxy and typecast
vgarmash Apr 10, 2011 8:54 PM (in response to porcherg)Yes - you need ProxyVisitorPattern: http://community.jboss.org/wiki/ProxyVisitorPattern because lazy polymorphic are proxies and not your types.
Other solution: split you entity class to interface and implementation so then in mapping subclasses you can specify the interface name in proxy attribute. See
5.1.17. Subclass in hibernate reference.