我有两个实体类
class User {
Integer userId;
String userName;
UserType userType;
}
和
class UserType {
Integer typeId;
String type;
Set<User> userList;
}
如何在通过 HQL 更新查询user.userType=null
的所有user.userType
中设置new UserType()
?
我是冬眠的新手。
你可以做这样的事情:
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();