Hibernate Custom HQL Update Type

Is it possible to update a custom type field in an HQL query?

When I try to use the user type in where where, 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 try to use the user type as the field to update, I get an exception. It seems that hibernate is trying to translate the "position" into the sql string "position_x =?" And position_y =? And position_z =? "in any case, even in the installed part of the 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 mistake. Still unresolved. http://opensource.atlassian.com/projects/hibernate/browse/HHH-5936

+4
source share

Source: https://habr.com/ru/post/1347207/


All Articles