尝试使用使用 Hibernate 3.6 和 MySQL5.1 选择实体,但我不断收到 ClassCastException。
@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
尝试在 createQuery() 中使用 HQL 时,我不断收到 ClassCastException:
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
我尝试使用 setResultTransformer(Transformers.aliasToBean(User.class)),但这给了我一个 NullPointerException。
不知道我做错了什么。