冬眠。 HQL更新用户类型
是否可以更新 HQL 查询中的用户类型字段?
当我尝试在 where 子句中使用用户类型时,一切正常。
getSession()
.createQuery("update " + AvatarDataSet.class.getName() + " set removed=false where id=:avatarId and position =:pos ")
.setParameter("pos", ds.getPosition(), Hibernate.custom(ConstPointUserType.class))
.setParameter("avatarId", ds.getPersistentId().getLongId())
.executeUpdate();
update avatar set is_removed=false where Id=? and position_x=? and position_y=? and position_z=?
但是当我尝试使用用户类型作为要更新的字段时,我遇到了异常。似乎hibernate正在尝试翻译sql字符串“position_x=?和position_y=?和position_z=?”中的“位置”占位符无论如何,即使在更新的设置部分... :(
getSession()
.createQuery("update " + AvatarDataSet.class.getName() + " set position = :pos where dbId=:avatarId")
.setParameter("pos", ds.getPosition(), Hibernate.custom(ConstPointUserType.class))
.setParameter("avatarId", ds.getPersistentId().getLongId())
.executeUpdate();
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: AND near line 1, column 51 [update dataSets.avatar.AvatarDataSet set position = :pos where dbId=:avatarId]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
.......
编辑:
这是一个错误。仍未解决。http://opensource.atlassian.com/projects/hibernate/browse/HHH-5936
Is it possible to update user type field in HQL query?
When I am trying to use user type in where clause everything works fine.
getSession()
.createQuery("update " + AvatarDataSet.class.getName() + " set removed=false where id=:avatarId and position =:pos ")
.setParameter("pos", ds.getPosition(), Hibernate.custom(ConstPointUserType.class))
.setParameter("avatarId", ds.getPersistentId().getLongId())
.executeUpdate();
update avatar set is_removed=false where Id=? and position_x=? and position_y=? and position_z=?
But when I am trying to use user type as a field to be updated I am getting an exception. Seems like hibernate is trying to translate "position" placeholder in sql string "position_x=? and position_y=? and position_z=?" in any case even in set part of update... :(
getSession()
.createQuery("update " + AvatarDataSet.class.getName() + " set position = :pos where dbId=:avatarId")
.setParameter("pos", ds.getPosition(), Hibernate.custom(ConstPointUserType.class))
.setParameter("avatarId", ds.getPersistentId().getLongId())
.executeUpdate();
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: AND near line 1, column 51 [update dataSets.avatar.AvatarDataSet set position = :pos where dbId=:avatarId]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
.......
Edit:
This is a bug. Still unresolved. http://opensource.atlassian.com/projects/hibernate/browse/HHH-5936
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论