当前位置:Gxlcms > mysql > 让Hibernate支持Oracle中的函数

让Hibernate支持Oracle中的函数

时间:2021-07-01 10:21:17 帮助过:42人阅读

The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead那是因为 Dialect 未

The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
那是因为 Dialect 未定义,重写类,把未定义的Dialect 注册一下即可,,
并且在 hibernate.cfg.xml中加入

org.hibernate.dialect.OracleCustomDialect

新建一个类叫OracleCustomDialect

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() );

linux

人气教程排行