在运行时休眠@Formula设置值

编程入门 行业动态 更新时间:2024-10-23 11:16:28
本文介绍了在运行时休眠@Formula设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Java实体,该实体的字段带有@Formula批注,在其中执行SQL查询,其中包含Firebird数据库的某些特定功能. 现在,我必须迁移到Oracle数据库,并且需要替换该@Formula中的SQL代码. 有办法实现吗?我可以通过某种方式扩展Hibernate @Formula以便在运行时更改注释的值吗? 谢谢

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 migrate to Oracle database, and I need to replace the SQL code inside that @Formula. Is there a way to achieve this ? Can I extend in some way the Hibernate @Formula in order to change the annotation's value at runtime ? Thanks

推荐答案

您可以实现这种略有不同的方式.

You can achieve this slightly different way.

您可以在@Formula中放置占位符"{TO_BE_REPLACED}"并添加一个Hibernate Interceptor来更改 onPrepareStatement . 在那里您可以更改由休眠生成的SQL. JUst检查SQL字符串并将{TO_BE_REPLACED}替换为您的实际值.

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.

在此处

更多推荐

在运行时休眠@Formula设置值

本文发布于:2023-06-10 22:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Formula

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!