今天遇到这样的问题:
The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
在网上搜集了一下资料,原来是方言的问题。遂转载过来,方便以后继续学习。
Hibernate 不同数据库的连接及SQL方言
<!--MySql 驱动程序 eg. mysql-connector-java-5.0.4-bin.jar-->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- JDBC URL -->
<property name="connection.url">jdbc:mysql://localhost/dbname?characterEncoding=gb2312</property>
<!-- 数据库用户名-->
<property name="connection.username">root</property>
<!-- 数据库密码-->
<property name="connection.password">root</property>
<!--Sql Server 驱动程序 eg. jtds-1.2.jar-->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<!-- JDBC URL -->
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=dbname</property>
<!-- 数据库用户名-->
<property name="connection.username">sa</property>
<!-- 数据库密码-->
<property name="connection.password"></property>
<!--Oracle 驱动程序 ojdbc14.jar-->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- JDBC URL -->
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:dbname</property>
<!-- 数据库用户名-->
<property name="connection.username">test</property>
<!-- 数据库密码-->
<property name="connection.password">test</property>
原文网址:http://www.fengfly.com/plus/view-168177-1.html
如果出现如下错误,则可能是Hibernate SQL方言 (hibernate.dialect)设置不正确。
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]'last_insert_id' 不是可以识别的 函数名。
RDBMS 方言
DB2 org.hibernate.dialect.DB2Dialect
DB2 AS/400 org.hibernate.dialect.DB2400Dialect
DB2 OS390 org.hibernate.dialect.DB2390Dialect
PostgreSQL org.hibernate.dialect.PostgreSQLDialect
MySQL org.hibernate.dialect.MySQLDialect
MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version) org.hibernate.dialect.OracleDialect
Oracle 9i/10g org.hibernate.dialect.Oracle9Dialect
Sybase org.hibernate.dialect.SybaseDialect
Sybase Anywhere org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server org.hibernate.dialect.SQLServerDialect
SAP DB org.hibernate.dialect.SAPDBDialect
Informix org.hibernate.dialect.InformixDialect
HypersonicSQL org.hibernate.dialect.HSQLDialect
Ingres org.hibernate.dialect.IngresDialect
Progress org.hibernate.dialect.ProgressDialect
Mckoi SQL org.hibernate.dialect.MckoiDialect
Interbase org.hibernate.dialect.InterbaseDialect
Pointbase org.hibernate.dialect.PointbaseDialect
FrontBase org.hibernate.dialect.FrontbaseDialect
Firebird org.hibernate.dialect.FirebirdDialect
原文网址:http://www.fengfly.com/plus/view-168177-1.html
有时候,hibernate用原生SQL 查询,native SQL 的时候,会出现
org.hibernate.MappingException: No Dialect mapping for JDBC type: -1 ,-16,等等的错误
type 类型代码 可以看 java.sql.Types 中的定义,看源码就可以了
那是因为 Dialect 未定义,重写类,把未定义的Dialect 注册一下即可,
并且在 hibernate.cfg.xml中加入
Xml代码
<property name="hibernate.dialect">
org.hibernate.dialect.OracleCustomDialect
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.OracleCustomDialect
</property>
Java代码
import java.sql.Types;
import org.hibernate.Hibernate;
public class OracleCustomDialect extends org.hibernate.dialect.Oracle10gDialect {
public OracleCustomDialect() {
super();
registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName());
}
}
import java.sql.Types;
import org.hibernate.Hibernate;
public class OracleCustomDialect extends org.hibernate.dialect.Oracle10gDialect {
public OracleCustomDialect() {
super();
registerHibernateType(Types.FLOAT, Hibernate.FLOAT.getName());
}
}
这是自己解决的折中办法,最好还是遵循标准类型
在hibernate中,Oracle9Dialect 方言定义有以下代码:
Java代码
public class Oracle9Dialect extends Dialect {
private static final Logger log = LoggerFactory.getLogger( Oracle9Dialect.class );
public Oracle9Dialect() {
super();
log.warn( "The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead" );
registerColumnType( Types.BIT, "number(1,0)" );
registerColumnType( Types.BIGINT, "number(19,0)" );
registerColumnType( Types.SMALLINT, "number(5,0)" );
registerColumnType( Types.TINYINT, "number(3,0)" );
registerColumnType( Types.INTEGER, "number(10,0)" );
registerColumnType( Types.CHAR, "char(1 char)" );
registerColumnType( Types.VARCHAR, 4000, "varchar2($l char)" );
registerColumnType( Types.VARCHAR, "long" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double precision" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "date" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARBINARY, 2000, "raw($l)" );
registerColumnType( Types.VARBINARY, "long raw" );
registerColumnType( Types.NUMERIC, "number($p,$s)" );
registerColumnType( Types.DECIMAL, "number($p,$s)" );
registerColumnType( Types.BLOB, "blob" );
registerColumnType( Types.CLOB, "clob" );
……
……
public class Oracle9Dialect extends Dialect {
private static final Logger log = LoggerFactory.getLogger( Oracle9Dialect.class );
public Oracle9Dialect() {
super();
log.warn( "The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead" );
registerColumnType( Types.BIT, "number(1,0)" );
registerColumnType( Types.BIGINT, "number(19,0)" );
registerColumnType( Types.SMALLINT, "number(5,0)" );
registerColumnType( Types.TINYINT, "number(3,0)" );
registerColumnType( Types.INTEGER, "number(10,0)" );
registerColumnType( Types.CHAR, "char(1 char)" );
registerColumnType( Types.VARCHAR, 4000, "varchar2($l char)" );
registerColumnType( Types.VARCHAR, "long" );
registerColumnType( Types.FLOAT, "float" );
registerColumnType( Types.DOUBLE, "double precision" );
registerColumnType( Types.DATE, "date" );
registerColumnType( Types.TIME, "date" );
registerColumnType( Types.TIMESTAMP, "timestamp" );
registerColumnType( Types.VARBINARY, 2000, "raw($l)" );
registerColumnType( Types.VARBINARY, "long raw" );
registerColumnType( Types.NUMERIC, "number($p,$s)" );
registerColumnType( Types.DECIMAL, "number($p,$s)" );
registerColumnType( Types.BLOB, "blob" );
registerColumnType( Types.CLOB, "clob" );
……
……
而hibernate 3.3.2中 带的Oracle10gDialect方言代码如下,是继承了 Oracle9Dialect
Java代码
public class Oracle10gDialect extends Oracle9iDialect {
public Oracle10gDialect() {
super();
}
public JoinFragment createOuterJoinFragment() {
return new ANSIJoinFragment();
}
}
public class Oracle10gDialect extends Oracle9iDialect {
public Oracle10gDialect() {
super();
}
public JoinFragment createOuterJoinFragment() {
return new ANSIJoinFragment();
}
}
同时,在public abstract class Dialect 类中,定义了以下registerHibernateType, 所有的数据库类型的Dialect都是 extends Dialect
Java代码
protected Dialect() {
log.info( "Using dialect: " + this );
sqlFunctions.putAll( STANDARD_AGGREGATE_FUNCTIONS );
// standard sql92 functions (can be overridden by subclasses)
registerFunction( "substring", new SQLFunctionTemplate( Hibernate.STRING, "substring(?1, ?2, ?3)" ) );
registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "locate(?1, ?2, ?3)" ) );
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );
registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
registerFunction( "bit_length", new StandardSQLFunction( "bit_length", Hibernate.INTEGER ) );
registerFunction( "coalesce", new StandardSQLFunction( "coalesce" ) );
registerFunction( "nullif", new StandardSQLFunction( "nullif" ) );
registerFunction( "abs", new StandardSQLFunction( "abs" ) );
registerFunction( "mod", new StandardSQLFunction( "mod", Hibernate.INTEGER) );
registerFunction( "sqrt", new StandardSQLFunction( "sqrt", Hibernate.DOUBLE) );
registerFunction( "upper", new StandardSQLFunction("upper") );
registerFunction( "lower", new StandardSQLFunction("lower") );
registerFunction( "cast", new CastFunction() );
registerFunction( "extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)") );
//map second/minute/hour/day/month/year to ANSI extract(), override on subclasses
registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)") );
registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)") );
registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)") );
registerFunction( "day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)") );
registerFunction( "month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)") );
registerFunction( "year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)") );
registerFunction( "str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)") );
// register hibernate types for default use in scalar sqlquery type auto detection
registerHibernateType( Types.BIGINT, Hibernate.BIG_INTEGER.getName() );
registerHibernateType( Types.BINARY, Hibernate.BINARY.getName() );
registerHibernateType( Types.BIT, Hibernate.BOOLEAN.getName() );
registerHibernateType( Types.CHAR, Hibernate.CHARACTER.getName() );
registerHibernateType( Types.DATE, Hibernate.DATE.getName() );
registerHibernateType( Types.DOUBLE, Hibernate.DOUBLE.getName() );
registerHibernateType( Types.FLOAT, Hibernate.FLOAT.getName() );
registerHibernateType( Types.INTEGER, Hibernate.INTEGER.getName() );
registerHibernateType( Types.SMALLINT, Hibernate.SHORT.getName() );
registerHibernateType( Types.TINYINT, Hibernate.BYTE.getName() );
registerHibernateType( Types.TIME, Hibernate.TIME.getName() );
registerHibernateType( Types.TIMESTAMP, Hibernate.TIMESTAMP.getName() );
registerHibernateType( Types.VARCHAR, Hibernate.STRING.getName() );
registerHibernateType( Types.VARBINARY, Hibernate.BINARY.getName() );
registerHibernateType( Types.NUMERIC, Hibernate.BIG_DECIMAL.getName() );
registerHibernateType( Types.DECIMAL, Hibernate.BIG_DECIMAL.getName() );
registerHibernateType( Types.BLOB, Hibernate.BLOB.getName() );
registerHibernateType( Types.CLOB, Hibernate.CLOB.getName() );
registerHibernateType( Types.REAL, Hibernate.FLOAT.getName() );
protected Dialect() {
log.info( "Using dialect: " + this );
sqlFunctions.putAll( STANDARD_AGGREGATE_FUNCTIONS );
// standard sql92 functions (can be overridden by subclasses)
registerFunction( "substring", new SQLFunctionTemplate( Hibernate.STRING, "substring(?1, ?2, ?3)" ) );
registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "locate(?1, ?2, ?3)" ) );
registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );
registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
registerFunction( "bit_length", new StandardSQLFunction( "bit_length", Hibernate.INTEGER ) );
registerFunction( "coalesce", new StandardSQLFunction( "coalesce" ) );
registerFunction( "nullif", new StandardSQLFunction( "nullif" ) );
registerFunction( "abs", new StandardSQLFunction( "abs" ) );
registerFunction( "mod", new StandardSQLFunction( "mod", Hibernate.INTEGER) );
registerFunction( "sqrt", new StandardSQLFunction( "sqrt", Hibernate.DOUBLE) );
registerFunction( "upper", new StandardSQLFunction("upper") );
registerFunction( "lower", new StandardSQLFunction("lower") );
registerFunction( "cast", new CastFunction() );
registerFunction( "extract", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(?1 ?2 ?3)") );
//map second/minute/hour/day/month/year to ANSI extract(), override on subclasses
registerFunction( "second", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(second from ?1)") );
registerFunction( "minute", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(minute from ?1)") );
registerFunction( "hour", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(hour from ?1)") );
registerFunction( "day", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(day from ?1)") );
registerFunction( "month", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(month from ?1)") );
registerFunction( "year", new SQLFunctionTemplate(Hibernate.INTEGER, "extract(year from ?1)") );
registerFunction( "str", new SQLFunctionTemplate(Hibernate.STRING, "cast(?1 as char)") );
// register hibernate types for default use in scalar sqlquery type auto detection
registerHibernateType( Types.BIGINT, Hibernate.BIG_INTEGER.getName() );
registerHibernateType( Types.BINARY, Hibernate.BINARY.getName() );
registerHibernateType( Types.BIT, Hibernate.BOOLEAN.getName() );
registerHibernateType( Types.CHAR, Hibernate.CHARACTER.getName() );
registerHibernateType( Types.DATE, Hibernate.DATE.getName() );
registerHibernateType( Types.DOUBLE, Hibernate.DOUBLE.getName() );
registerHibernateType( Types.FLOAT, Hibernate.FLOAT.getName() );
registerHibernateType( Types.INTEGER, Hibernate.INTEGER.getName() );
registerHibernateType( Types.SMALLINT, Hibernate.SHORT.getName() );
registerHibernateType( Types.TINYINT, Hibernate.BYTE.getName() );
registerHibernateType( Types.TIME, Hibernate.TIME.getName() );
registerHibernateType( Types.TIMESTAMP, Hibernate.TIMESTAMP.getName() );
registerHibernateType( Types.VARCHAR, Hibernate.STRING.getName() );
registerHibernateType( Types.VARBINARY, Hibernate.BINARY.getName() );
registerHibernateType( Types.NUMERIC, Hibernate.BIG_DECIMAL.getName() );
registerHibernateType( Types.DECIMAL, Hibernate.BIG_DECIMAL.getName() );
registerHibernateType( Types.BLOB, Hibernate.BLOB.getName() );
registerHibernateType( Types.CLOB, Hibernate.CLOB.getName() );
registerHibernateType( Types.REAL, Hibernate.FLOAT.getName() );
如果有特殊类型确实需要,只能自定义。
所以oracle的类型定义最好遵循以上的 java.sql.Types,
在hibernate.cfg.xml中使用 org.hibernate.dialect.OracleCustomDialect
以防出现No Dialect mapping for JDBC type错误
其他的 数据库类型,SQL SERVER DB2 MYSQL 等等,都可以查看 hibernate的相关源码找出个所以然来
原文网址:http://www.fengfly.com/plus/view-168177-1.html
分享到:
相关推荐
达梦数据库各版本的hibernate方言包,包含版本 DmDialect-for-hibernate2.0、DmDialect-for-hibernate2.1、DmDialect-for-hibernate3.0、DmDialect-for-hibernate3.1、DmDialect-for-hibernate3.6、DmDialect-for-...
《达梦Hibernate方言 2.0 至 4.0》是针对国产数据库达梦在Hibernate框架中的方言应用进行深入探讨的技术资料。Hibernate是一个流行的Java持久化框架,它简化了数据库与应用程序之间的交互,通过对象关系映射(ORM)...
这里我们关注的是“达梦Hibernate方言2.0至4.0”,这是一个专为达梦数据库系统(DM)设计的Hibernate方言支持,涵盖了Hibernate框架的多个版本。Hibernate是一个流行的Java对象关系映射(ORM)框架,它允许开发人员...
hibernate方言包
* 达梦8 hibernate方言包对应版本说明 /*************************************** jar包在dialect目录下: 1. DmDialect-for-hibernate2.0.jar 对应 Jdk1.4及以上, hibernate2.0 环境 2. DmDialect-for-hibernate2.1...
Hibernate方言是Hibernate ORM框架中的一个重要组成部分,它负责与各种数据库管理系统进行通信时的SQL语句转换。在Hibernate中,方言(Dialect)是用于定义特定数据库的SQL语法、特性以及限制的一个类。当Hibernate...
sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言sqllite3 hibernate 方言
在探讨Hibernate中所有数据库方言之前,我们先简要回顾一下Hibernate框架本身。...此外,方言的存在还帮助开发者避免了因数据库特定语法带来的兼容性问题,使应用能够在多种数据库环境中稳定运行。
在压缩包中提供的Hibernate方言包,适用于Hibernate 5.3及以下版本,这意味着即使你的项目使用的是较早版本的Hibernate,也能顺利地与达梦数据库进行集成。 使用这些驱动和方言包,开发者可以方便地在Java应用中...
瀚高数据库Hibernate方言是针对瀚高数据库(HighGo Database)设计的一种特定的方言实现,用于在Java应用程序中通过Hibernate框架与瀚高数据库进行交互。Hibernate是一个流行的对象关系映射(ORM)工具,它允许开发者...
Hibernate不同数据库的连接及SQL方言 在Hibernate中,连接不同的数据库需要使用不同的数据库连接驱动程序和SQL方言。下面我们将详细介绍如何在Hibernate中连接不同的数据库。 首先,Hibernate提供了一些基本的...
Hibernate连接SQLite配置步骤: 1、添加SQLite库: 1.1、将两个jar包:com.zy.hibernate.dialect.SQLiteDialect.jar、sqlite-jdbc-3.7.2.jar拷贝到“\WEB-INF\lib”文件夹下; 2、配置hibernate: 2.1、将...
### Hibernate方言概述 在Java开发领域,特别是针对企业级应用的持久层操作中,Hibernate作为一款优秀的ORM(Object Relational Mapping)框架,被广泛应用于数据访问层。在配置Hibernate时,一个重要的参数是`...
达梦数据库7最新版驱动Dm7JdbcDriver18及hibernate5.0方言包,是针对达梦数据库管理系统(DM7)与Java应用程序交互的重要组件。这个压缩包包含两个关键文件:`Dm7JdbcDriver18-7.6.0.142.jar`和`DmDialect-for-...
为了解决这个问题,我们需要自定义或者扩展Hibernate的方言类,让其知道如何处理`TEXT`字段。`MYSQLDialect.java`就是这样一个类,它通常位于Hibernate的源码库中,负责定义MySQL数据库特有的SQL语法和特性。在...
该项目为openGauss数据库的Hibernate方言包设计源码,包含82个文件,主要由70个Java源文件和9个XML配置文件构成,还包括2个Git忽略文件和1个PDF文档。该方言包旨在提供Java语言环境下与openGauss数据库的集成支持。