Reputation: 1911
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.
Upvotes: 2
Views: 2231
Reputation: 1911
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 ...
Upvotes: 1
Reputation: 109547
See MySQL DELETE - there is no syntax definition for an alias in DELETE.
Upvotes: 3