Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're not providing the problem code, (or the full stack trace) but the rundown is this:</p> <p>When you annotate a class as @Transactional, and Spring creates an instance for you, what you get is not that class, but a Java Dynamic Proxy that implements that classes' interfaces. <a href="http://download.oracle.com/javase/1.3/docs/guide/reflection/proxy.html" rel="nofollow noreferrer">http://download.oracle.com/javase/1.3/docs/guide/reflection/proxy.html</a></p> <p>Because of this, you cannot cast that object to the original type (it's not that type anymore!) and must use it's interface(s) instead.</p> <p>If there aren't interfaces to implement, it will give you a CGLib proxy of the class, which is basically just a runtime modified version of your class, and so is assignable to the class itself.</p> <p>Search for where you're injecting, or casting to type UserDaoImpl, and change the reference to UserDao instead, and it will work properly.</p> <p>I've read the performance difference between CGLib proxies and Dynamic Java Proxies is quite minimal, so you can also add the following to your spring config to force it to use CGLib proxies instead of Java Dynamic Proxies:</p> <pre><code>&lt;aop:config proxy-target-class="true"&gt; </code></pre> <p>In general however, I'd recommend you not use CGLib Proxies, but instead access your class from its interface. Loose coupling will allow you to do runtime substitution, and limits your ability to accidentally introduce brittle class dependencies.</p> <p>There are some problems that using Java Dynamic Proxies will introduce however, and what you're doing is close enough to what I was doing that you should be aware of this:</p> <p><a href="https://stackoverflow.com/questions/4929044/how-to-use-dynamic-proxies-with-jsf-when-the-method-signature-contains-object">How to use Dynamic Proxies with JSF when the method signature contains Object ... args</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload