title: Hibernate createQuery() throws ClassCastException, Transformer doesn't help
body: <p>Trying to SELECT an entity using Using Hibernate 3.6 and MySQL5.1 but I keep getting a ClassCastException.</p>
  
  <pre><code>@Entity
  @Table( name = "USER" )
  public class User {
     @Id
     @Column(name= "user_id")
     private Long userId;
  
     @OneToOne()
     @JoinColumn(name="status_id")
     protected UserStatusType userStatusType;
  
     @OneToOne()
     @JoinColumn(name="region_id")
     protected Region region;
  
  
  @Entity
  @Table( name = "REGION" )
  public class Region   
     @Id
     @Column(name = "region_id")
     private Long regionId
  
  
  @Entity
  @Table( name = "USER_STATUS_TYPE" )
  public class UserStatusType  
     @Id
     @Column(name = "type_id")
     private Long typeId
  </code></pre>
  
  <p>When attempting to use HQL in createQuery() I keep getting a ClassCastException:</p>
  
  <pre><code>session.beginTransaction();
  User user = (User)session.createQuery(
     "from User u, UserStatusType ust, Region r "
     + " where u.userId = ? and u.userStatusType.typeId = ust.typeId"
     + " and u.region.regionId = r.regionId")
     .setLong(0, 42L)                     
     .uniqueResult();
  
  
   java.lang.ClassCastException:
  [Ljava.lang.Object; cannot be cast to com.scd.dao.entity.User
  </code></pre>
  
  <p>I tried using setResultTransformer(Transformers.aliasToBean(User.class)), but that gave me a NullPointerException.</p>
  
  <p>Not sure what I'm doing wrong.</p>