Hibernate @Formula set value at runtime

后端 未结 1 1865
逝去的感伤
逝去的感伤 2021-01-06 08:47

I have a Java Entity with a field with the annotation @Formula, in which is executed an SQL query containing some specific function for Firebird database. Now I have to migr

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 09:05

    You can achieve this slightly different way.

    You can place in the @Formula a placeholder "{TO_BE_REPLACED}" and add a Hibernate Interceptor to change onPrepareStatement. There you can can change SQL generated by hibernate. JUst check the SQL string and replace the {TO_BE_REPLACED} with your real value.

    See how to add interceptor here

    0 讨论(0)
提交回复
热议问题