0

我已将我的关系 bbdd 表映射到 Java 对象。

@Entity
@Table(name = "user")
public class User implements Serializable{

// Another attributes...
@OneToOne
@JoinColumn(name = "id")
private UserAccount userAccount;

// Getters and setters...

}

@Entity
@Table(name = "user_account")
public class UserAccount implements Serializable{

@Id
@GenericGenerator(name = "generator", strategy = "foreign",
        parameters =
        @Parameter(name = "property", value = "user"))
@GeneratedValue(generator = "generator")
@Column(name = "user_id", unique = true, nullable = false)
private int user_id;
// Another attributes...

// Getters and setters...

}

我有一个这样的标准。

Criterion crit = Restrictions.and(
                Restrictions.like("userAccount.email", email),
                Restrictions.like("userAccount.password", MD5.crypt(password)));

但我得到这个错误。

org.hibernate.QueryException: could not resolve property: User of: com.mypackage.entity.User

如何通过标准从用户访问 UserAccount.email?

4

1 回答 1

1

您必须为每个连接创建一个新条件:

Criteria criteria = session.createCriteria(User.class)
        .createCriteria("userAccount").add(Restrictions.and(
                Restrictions.like("email", email),
                Restrictions.like("password", MD5.crypt(password)));d
于 2013-08-09T08:12:45.973 回答