gpt4 book ai didi

hibernate - 使用 hibernate 解析 SQL 方言

转载 作者:行者123 更新时间:2023-12-03 13:01:57 24 4
gpt4 key购买 nike

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

最佳答案

最后我找到了方法 - 但它是特定于 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")){
....

关于hibernate - 使用 hibernate 解析 SQL 方言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8742617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com