当前位置:  数据库>编程语言 iis7站长之家

让Hibernate支持Oracle中的函数

    来源: 互联网  发布时间:2017-05-16

    本文导语: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead那是因为 Dialect  未定义,重写类,把未定义的Dialect 注册一下即可,并且在 hibernate.cfg.xml中加入    org.hibernate.dialect.OracleCustomDialect 新建一个类叫Oracl...

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


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • java将类序列化并存储到mysql(使用hibernate)
  • linux图形模式下shutdown里有Hibernate这个选项。怎么man shutdown里找不到hibernate这个选项呢。
  • java 框架Hibernate的generator属性的七种class介绍
  • Hibernate搜索框架 Hibernate Search
  • struts+spring+hibernate+jquery实现分页功能的几个基本类介绍(异步加载)
  • Hibernate Shards
  • spring的事务类型及spring和hibernate可能导致的问题分析
  • Eclipse添加xml文件提示及Hibernate配置学习
  • 数据持久层框架 Hibernate
  • Eclipse的Hibernate插件 HiberClipse
  • Hibernate EntityManager
  • Bean验证框架 Hibernate Validator
  • hibernate能用在C++开发上吗?
  • Hibernate POJO Generator
  • Hibernate泛型DAO层 SwiftDAO
  • Hibernate Synchronizer
  • Hibernate映射文件生成工具 hbm2java
  • Hibernate-SQLite
  • NoSQL的持久层框架 Hibernate OGM
  • hibernate-memcached
  • Hibernate的JNDI绑定分析


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,