How to use Mysql variables with Hibernate?

后端 未结 3 1961
北荒
北荒 2020-12-11 09:40

I need to use a native sql query in Hibernate with use of variable.

But hibernate throws an error saying: Space is not allowed after parameter prefix

So ther

3条回答
  •  一整个雨季
    2020-12-11 10:19

    I'll copy paste my answer from https://stackoverflow.com/a/25552002/3987202

    Another solution for those of us who can't make the jump to Hibernate 4.1.3.
    Simply use /*'*/:=/*'*/ inside the query. Hibernate code treats everything between ' as a string (ignores it). MySQL on the other hand will ignore everything inside a blockquote and will evaluate the whole expression to an assignement operator.
    I know it's quick and dirty, but it get's the job done without stored procedures, interceptors etc.

提交回复
热议问题