0

我有两个实体类

class User { 
    Integer userId;
    String userName;
    UserType userType;
}

class UserType {
    Integer typeId;
    String type;
    Set<User> userList;
}

如何通过 HQL 更新查询new UserType()在所有user.userType位置进行设置?user.userType=null

我是冬眠新手。

4

1 回答 1

4

您可以执行以下操作:

UserType userType = /* code to get already persisted userType */;

Query query = session.createQuery("update User u set u.userType = :newType where u.userType is null");
query.setParameter("newType", userType);
int result = query.executeUpdate();
于 2012-06-14T18:46:16.800 回答