title: Proxy cannot be cast to CLASS
body: <p>I'm using Spring for wiring dependencies specifically for DAO classes that use Hibernate, but I'm getting an exception that has me puzzled:</p>
  
  <p><strong>$Proxy58 cannot be cast to UserDao</strong></p>
  
  <p>My DAO is configured as follows:</p>
  
  <pre><code>&lt;bean id="userDao" class="com.domain.app.dao.UserDao"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>And I have an interface, abstract base class and a final implementation as follows.</p>
  
  <p>Interface:</p>
  
  <pre><code>public interface Dao {
      public void save(Object object);
      public Object load(long id);
      public void delete(Object object);
      public void setSessionFactory(SessionFactory sessionFactory);
  }
  </code></pre>
  
  <p>Abstract Base Class:</p>
  
  <pre><code>public abstract class BaseDao implements Dao {
  
      private SessionFactory sessionFactory;
  
      @Transactional
      @Override
      public void save(Object object) {
          PersistentEntity obj = (PersistentEntity) object;
          currentSession().saveOrUpdate(obj);
      }
  
      @Transactional
      @Override
      public abstract Object load(long id);
  
      @Transactional
      @Override
      public void delete(Object object) {
          // TODO: this method!
      }
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      public Session currentSession() {
          return sessionFactory.getCurrentSession();
      }
  
  }
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>public class UserDao extends BaseDao implements Dao {
  
      @Transactional(readOnly=true)
      @Override
      public Object load(long id) {
          Object user = currentSession().get(User.class, id);
          return user;
      }
  
  }
  </code></pre>
  
  <p>The following throws the exception mentioned above:</p>
  
  <p><em>UserDao dao = (UserDao) context.getBean("userDao");</em></p>
  
  <p>This, however, does not throw an exception:</p>
  
  <p><em>Dao dao = (Dao) context.getBean("userDao");</em></p>
  
  <p>If anyone can offer any assistance or guidance as to why this exception is happening, I would be very appreciative.</p>