使用 JPA 和 Hibernate 注册 SQL 函数 [英] Registering a SQL function with JPA and Hibernate

查看:27
本文介绍了使用 JPA 和 Hibernate 注册 SQL 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用 JPA/Hibernate 注册自定义 SQL 函数的最佳方法是什么.

I would like to know what's the best way to register a custom SQL function with JPA/Hibernate.

我是否必须通过扩展 MysqlInnodb 方言或有更好的方法?

Do I have to go through extending the MysqlInnodb dialect or is there a better way?

谁能提供代码示例和相关文档的指针?

Can anyone please provide code samples and pointers to relevant documentation?

推荐答案

是的,扩展方言是注册自定义 SQL 函数的好方法.

Yes extending the dialect is a good way of registering custom SQL function.

在您的方言类构造函数中添加类似的内容.

Add something like this in your Dialect classes constructor.

registerFunction("current_timestamp", new NoArgSQLFunction(Hibernate.TIMESTAMP) );
registerFunction("date", new StandardSQLFunction(Hibernate.DATE) );

查看现有方言类之一的源代码..http://www.koders.com/java/fid0E7F787E2EC52F1DA8DFD264EDFBD2DE904A0927.aspxcom/java/fid0E7F787E2EC52F1DA8DFD264EDFBD2DE904A0927.aspx

Look at the source code of one of the existing dialect classes. http://www.koders.com/java/fid0E7F787E2EC52F1DA8DFD264EDFBD2DE904A0927.aspx

这篇关于使用 JPA 和 Hibernate 注册 SQL 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆