'Hibernate NamedQuery UPDATE statement throws QuerySyntaxException
I encountered a very interesting issue. I want to create an UPDATE
statement NamedQuery
for my class (I know this is a bit hacky).
The weird thing is if I use positioned parameters in the query like ?1, ?2
etc. it works perfectly. However, if I want to use named parameters like :id
, it fails with the following error:
failed because of: org.hibernate.hql.internal.ast.QuerySyntaxException: expecting EOF, found 'consumingTxId' near line 1
.
I'm using Kotlin btw.
My entity:
class StateDetailEntity(
@Id
@Column(name = "issue_tx_id")
val issueTxId: String,
@Column(name = "consuming_tx_id")
val consumingTxId: String?
)
My named query:
NamedQuery(
name = "StateDetailEntity.consume",
query = "UPDATE StateDetailEntity SET " +
"consumingTxId = :consumingTxId " +
"WHERE issueTxId = :issueTxId " +
"AND consumingTxId IS NULL"
)
If I add an alias to the table and re-write the name query to like UPDATE StateDetailEntity s SET...
I get the following error:
org.hibernate.hql.internal.ast.QuerySyntaxException: expecting EOF, found 's'
.
The funny thing is if I change the query like this:
NamedQuery(
name = "StateDetailEntity.consume",
query = "UPDATE StateDetailEntity SET " +
"consumingTxId = ?1 " +
"WHERE issueTxId = ?2 " +
"AND consumingTxId IS NULL"
)
There are no issues at all. Any ideas? Using Hibernate 5.4.32.Final
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|