title: Spring @Transactional persist method not working
body: <p>I have a Spring MVC sample application it uses UserDaoImpl class to save a User type object to database. Following is the UserDaoImpl code.</p>
  
  <pre><code>public class UserDaoImpl implements UserDao&lt;User&gt; {
  
  private EntityManagerFactory emf;
  
  @PersistenceContext
  private EntityManager em;
  
  @Transactional
  public void saveUser(User user){
      em.persist(user);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and my UserDao interface looks like this.</p>
  
  <pre><code>public interface UserDao&lt;User&gt; {
  public void saveUser(User user);
  </code></pre>
  
  <p>}</p>
  
  <p>Weird thing is happening when when my UserDaoImpl class implements the UserDao interface. When trying to persist it gives the following error.</p>
  
  <pre><code>java.lang.ClassCastException: $Proxy71 cannot be cast to org.samith.UserDaoImpl
  </code></pre>
  
  <p>When I remove the "implements UserDao" part from the UserDaoImpl class user is persisted to database as expected.</p>
  
  <p>Also I tried UserDao interface without User parameter(that is non generic version). Still above error occurs. </p>
  
  <p>This may be a trivial question to answer but I am scratching my head finding a solution for about few hours.</p>
  
  <p>What wrong am I doing ??</p>