如何从hibernate模板获取dailect对象来操作db

时间:2015-10-08 10:57:23

标签: hibernate jdbc database-design

String driverName = this.getSession().connection().getMetaData().getDriverName();
if (driverName.contains(Const.DATABASE_SQLSERVER)) {
    ps = this.getSession().connection()
            .prepareStatement("select next value for " + seqName + " as nextval");
} else if (driverName.contains(Const.DATABASE_ORACLE)) {
    ps = this.getSession().connection()
             .prepareStatement("select " + seqName + ".nextval from dual");
} else if (driverName.contains(Const.DATABASE_MYSQL)) {
   //...
}

由于

1 个答案:

答案 0 :(得分:0)

您可以按以下方式获取信息:

    SessionFactoryImpl factoryImpl = (SessionFactoryImpl)sessionFactoryObject; 
    Properties properties = factoryImpl.getProperties();
    String dialect = properties.get("dialect").toString();