本文介绍了在运行时休眠@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设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:12