手机版
你好,游客 登录 注册
背景:
阅读新闻

让Hibernate支持Oracle中的函数

[日期:2013-02-01] 来源:Linux社区  作者:jelly_8090 [字体:大 中 小]

The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
那是因为 Dialect  未定义,重写类,把未定义的Dialect 注册一下即可,
并且在 hibernate.cfg.xml中加入
<property name="hibernate.dialect">
    org.hibernate.dialect.OracleCustomDialect
</property>
新建一个类叫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)") );

&nbsp;// 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相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       Oracle函数  hibernate  hibernate函数 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款