This one does not work:
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE FROM FileSet f WHERE f.file_id = :fileId</query>
</named-native-query>
It gives this error:
ERROR: You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near
'f WHERE f.file_id = 692' at line 1
While this statement works perfectly (without the table alias):
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE FROM FileSet WHERE file_id = :fileId</query>
</named-native-query>
Why? I'm using MySQL and Hibernate as JPA provider.
请参见MySQL DELETE - DELETE中没有别名的语法定义。
Apparently, this query works:
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE f FROM FileSet f WHERE f.file_id = :fileId</query>
</named-native-query>
The MySQL docs only mention this far down the page:
If you declare an alias for a table, you must use the alias when referring to the table:
DELETE t1 FROM test AS t1, test2 WHERE ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.