[英]Hibernate HQL Alias Issue
MainTable.java extends Common.java private Long id ; private Long version ; private String name ; private SubTable sub ; SubTable.java extends Common.java private String subname ; prviate String dualname ; Common.java private Long id ; prviate Date createDate ; HQL v String sql = "update MainTable set name = ? where sub.id = ? and version = ?" ; Query query = session..createQuery(sql); // set paramerts query.executeUpdate();
Hibernate Generated SQL Hibernate生成的SQL
update MainTable set name =? 更新MainTable集名称=? where templateve0_.SUB_ID=?
其中templateve0_.SUB_ID =? and version =?
和版本=?
Error 错误
ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "TEMPLATEVE0_"."SUB_ID": invalid identifier 错误org.hibernate.util.JDBCExceptionReporter-ORA-00904:“ TEMPLATEVE0 _”。“ SUB_ID”:无效的标识符
FYI - SUB_ID is a valid column name. 仅供参考-SUB_ID是有效的列名。
I am not sure why is hibernate adding templateve0_ alias only for the sub-object. 我不确定为什么休眠只为子对象添加templateve0_别名。 Any help?
有什么帮助吗?
Original - String sql = "update MainTable set name = ? where sub.id = ? and version = ?" 原始-字符串sql =“更新MainTable集名称=?,其中sub.id =?和version =?” ;
;
Updated String sql = "update MainTable set name = ? where SUB_ID = ? and version = ?" 更新的字符串sql =“更新MainTable集名称=?,其中SUB_ID =?和version =?” ;
;
I replaced sub.id with the actual column name and it seems to be working! 我用实际的列名替换了sub.id,它似乎正在工作! Very Strange!
很奇怪!
Try adding an alias to the root entity: 尝试向根实体添加别名:
update MainTable m set m.name = :name where m.sub.id = :id and m.version = :version
(NOTE: I prefer named vars to ordinal ones) (注意:我更喜欢使用命名变量而不是顺序变量)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.