使用休眠解决SQL方言 [英] Resolve SQL dialect using hibernate

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

问题描述

我负责将现有的项目从Oracle移植到MSSQL,但保持两种功能。
传统项目使用Hibernate 3.x,但包含一些复杂的本机查询。
所以我想知道使用哪种方言。

I'm responsible on porting existing project from Oracle to MSSQL, but keeping both functional. Legacy project uses Hibernate 3.x, but contains some number of sophisticated native queries. So I would like to know which dialect used.

推荐答案

我终于找到了方法 - 但它是特定于Hibernate的。

At last I've found the way - but it is specific for Hibernate.

//take from current EntityManager current DB Session
Session session = (Session) em.getDelegate();
//Hibernate's SessionFactoryImpl has property 'getDialect', to
//access this I'm using property accessor:
Object dialect = 
       org.apache.commons.beanutils.PropertyUtils.getProperty(
          session.getSessionFactory(), "dialect");
//now this object can be casted to readable string:
if( dialect.toString().contains("Oracle")){
   ....

这篇关于使用休眠解决SQL方言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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