[jboss-user] [JBoss Seam] - Re: coerceToType / javaassist error

paulkossler do-not-reply at jboss.com
Mon Oct 15 13:43:58 EDT 2007


Many of us have come across this error.  It seems to be caused by a flaw in the Directions for the JPA (which is Based on Hibernate) and Hibernate. They all assume you can use the proxy directly.  You can't!   The problem is direct use of a proxy object  fails the GoF Pattern for proxies.  Proxies  REQUIRE an interface.

The issue is "Subject isNotA SubjectProxy".
Its not an EL issue.  The AspectGenerated Proxy is following the GoF Proxy definition.  The flaw is that everyone seems to be using the Proxy wrong.  (Even his highness, Gavin King.)  Read the books on the subject and the documentation and the forums.  It is assumed that you can directly use the proxy asA subject;  by definition this is an incorrect assumption.

 
Define a proper proxy-pattern it passes the "coerceToType" method from EL.  Subj implements ISubj, Proxy implements ISubj.  Therefore Subj isA ISubj and Proxy isA ISubj.  Then when the coerceToType trys to make reconstitute the values in the ISubj it works because then the Proxy passes the critical isA test (Specifically isAssignableFrom())

ENOUGH TECH PAUL WHATS THE SOLUTION.  (I know I say it my head)

QUICK AND DIRTY (REALLY DIRTY)
The quickest solution to this problem is to tell JPA or Hibernate to not use a Proxy.  I know this causes serious issues: Less caching, dirty checks, lazy loading and all that lovely stuff.  

PROPER SOLUTION:
The proper solution is "Design By Interface"  and only reference the interface.  Alas the Hibernate implementation has some mapping issues with this approach.  (Cross mapping a storage solution via an interface can not be annotated currently, also the XML mappings seem to require double mapping of entities to the interfaces: note I am not sure on the latter)

These may be mitigated by defining the interface as the proxy

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095347#4095347

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095347



More information about the jboss-user mailing list