调用一个在休眠状态下返回varchar的mysql函数 [英] calling a mysql function returning varchar in hibernate
问题描述
我试图在hibernate中使用mysql find_in_set
字符串函数,但不幸的是我无法使用它,甚至尝试创建这些寄存器函数。 b
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));
使用mysqldialect,但没有人正在工作..任何人都可以告诉我如何使用mysql字符串函数在休眠。或者对上述寄存器功能进行任何更改。
在此先感谢,
最好的问候,
Raja。
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,新的StandardSQLFunction(group_concat,Hibernate.STRING));
}
}
并在查询中像这样使用它。
$ b $ pre $ new Query(> = date_sub_interval(CURRENT_DATE(),1,DAY)) ;
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)");
这篇关于调用一个在休眠状态下返回varchar的mysql函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!