Reputation: 5464
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
update MainTable set name =? where templateve0_.SUB_ID=? and version =?
Error
ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "TEMPLATEVE0_"."SUB_ID": invalid identifier
FYI - SUB_ID is a valid column name.
I am not sure why is hibernate adding templateve0_ alias only for the sub-object. Any help?
Upvotes: 2
Views: 3280
Reputation: 5464
Original - String sql = "update MainTable set name = ? where sub.id = ? and version = ?" ;
Updated String sql = "update MainTable set name = ? where SUB_ID = ? and version = ?" ;
I replaced sub.id with the actual column name and it seems to be working! Very Strange!
Upvotes: 1
Reputation: 9265
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)
Upvotes: 0