mysql varchar函数,调用一个在休眠状态下返回varchar的mysql函数

I am trying to use mysql find_in_set string function in hibernate but unfortunately I cant able to use it and even tried by creating these register functions

registerFunction("findInSet",newSQLFunctionTemplate(Hibernate.STRING,"FIND_IN_SET(?1,?2)"));

registerFunction("findInSet",newSQLFunctionTemplate(Hibernate.INTEGER,"FIND_IN_SET(?1,?2)"));

registerFunction("findInSet",new StandardSQLFunction("find_in_set", Hibernate.INTEGER));

using mysqldialect but no one is working..can any one please tell me how to use the mysql string functions in hibernate. or any changes to the above register functions.

Thanks in Advance,

Best Regards,

Raja.

解决方案

created a class by extending mysqldialect like shown below

public class MySqlDialectExtended extends MySQLDialect {

public MySqlDialectExtended() {

super();

registerFunction("date_add_interval", new SQLFunctionTemplate(Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)"));

registerFunction("date_sub_interval", new SQLFunctionTemplate(Hibernate.DATE, "DATE_SUB(?1, INTERVAL ?2 ?3)"));

registerFunction("weekofyear", new StandardSQLFunction("weekofyear", Hibernate.INTEGER));

registerFunction("group_concat", new StandardSQLFunction("group_concat", Hibernate.STRING));

}

}

and used it like this in query

new Query(" >= date_sub_interval(CURRENT_DATE(),1, DAY)");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值