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 が発生しました。
私が間違っているのかわかりません。