使用JPA / Hibernate注册SQL函数 [英] Registering a SQL function with JPA/Hibernate
本文介绍了使用JPA / Hibernate注册SQL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道使用JPA / Hibernate注册自定义SQL函数的最佳方法。
我必须去通过扩展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.
在您的Dialect类构造函数中添加类似内容。
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.aspx
Look at the source code of one of the existing dialect classes. http://www.koders.com/java/fid0E7F787E2EC52F1DA8DFD264EDFBD2DE904A0927.aspx
这篇关于使用JPA / Hibernate注册SQL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文