这个不起作用:
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE FROM FileSet f WHERE f.file_id = :fileId</query>
</named-native-query>
它给出了这个错误:
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
虽然这个陈述完美无缺(没有表别名):
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE FROM FileSet WHERE file_id = :fileId</query>
</named-native-query>
为什么呢?我正在使用MySQL和Hibernate作为JPA提供程序。
答案 0 :(得分:3)
请参阅MySQL DELETE - DELETE中没有别名的语法定义。
答案 1 :(得分:1)
显然,此查询有效:
<named-native-query name="FileSet.deleteByMemberId">
<query>DELETE f FROM FileSet f WHERE f.file_id = :fileId</query>
</named-native-query>
MySQL docs仅在页面下方提及:
如果声明表的别名,则在引用表时必须使用别名:
DELETE t1 FROM test AS t1, test2 WHERE ...