让Hibernate支持Oracle中的函数

本文介绍了如何解决Hibernate不支持Oracle中的特定函数的问题。通过创建一个名为OracleCustomDialect的自定义类,重写Dialect并注册Oracle特有的函数,如substring、locate、trim等,并在hibernate.cfg.xml配置文件中指定新的方言。这样,Hibernate就可以正确处理Oracle数据库中的函数了。
摘要由CSDN通过智能技术生成
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) );  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值