开发者

Hibernate. HQL update user type

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.QuerySyntaxExce开发者_JS百科ption: 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜