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