讓Hibernate支援Oracle中的函數

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.