title: Error when querying Hibernate entities
body: <p>I have two Hibernate entities as below with relationship between them and I am having problem querying them.</p>
  
  <pre><code>@Entity
  @Table(name="tdbs", catalog="dbcreator")
  public class DB extends DBEntity {
  
      @Id
      @Column(name="id", unique=true, nullable=false)
      @GenericGenerator(name="gen",strategy="increment")
      @GeneratedValue(generator="gen")
      private Integer id;
  
      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn(name="usr", referencedColumnName="usr", nullable=false)
      private User user;
  
  
  @Entity
  @Table(name="tusers",catalog="dbcreator", uniqueConstraints = @UniqueConstraint(columnNames="email"))
  @XmlRootElement(name = "User")
  public class User extends DBEntity {
  
      @Id 
      @Column(name="usr", unique=true, nullable=false, length=30)
      private String usr;
  </code></pre>
  
  <p>What I want to query for is to get the list of DB entities that are linked to particular user ("user" variable holds actual user name). I use below query:</p>
  
  <pre><code>List&lt;DB&gt; list = sessionFactory.getCurrentSession().createQuery(
                  "from DB p where p.user=:usrId").setString("usrId", user).list();
  </code></pre>
  
  <p>However this is giving me some strange error as below. Anyone has an idea how to get this sorted?</p>
  
  <pre><code>java.lang.ClassCastException: com.dbcreator.persistence.hibernate.model.User_$$_javassist_5 cannot be cast to javassist.util.proxy.Proxy
      at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:148)
      at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:73)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:758)
      at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4419)
      at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:333)
      at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:259)
      at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:944)
      at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:671)
      at org.hibernate.type.EntityType.resolve(EntityType.java:489)
      at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
      at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1112)
      at org.hibernate.loader.Loader.processResultSet(Loader.java:969)
      at org.hibernate.loader.Loader.doQuery(Loader.java:917)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
      at org.hibernate.loader.Loader.doList(Loader.java:2548)
      at org.hibernate.loader.Loader.doList(Loader.java:2534)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2364)
      at org.hibernate.loader.Loader.list(Loader.java:2359)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1194)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      at com.dbcreator.persistence.impl.DatabaseDAO.getDBList(DatabaseDAO.java:30)
  </code></pre>