How can I use MySQL assign operator(:=) in hibernate native query?

前端 未结 6 1530
情歌与酒
情歌与酒 2020-11-28 13:13

I\'m using Hibernate. I wrote some native query because I need to use sub select statement.

Query looks like this:

SELECT sub.rownum FROM 
    (SELEC         


        
6条回答
  •  -上瘾入骨i
    2020-11-28 14:19

    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.

提交回复
热议问题