开发者

SQL Replace in HQL

开发者 https://www.devze.com 2023-02-24 05:44 出处:网络
Any idea why this snippet of HQL would be failing.. REPLACE function requires three arguments is the error. Is t开发者_StackOverflow社区here any other way to perform a replace in HQL>?

Any idea why this snippet of HQL would be failing.. REPLACE function requires three arguments is the error. Is t开发者_StackOverflow社区here any other way to perform a replace in HQL>?

"WHERE :url LIKE ('%' || REPLACE(atf.title,'*','') || '%')" +


HQL does not support REPLACE function.

So you have to make your own custom dialect and register REPLACE function into it throught Dialect::registerFunction method

For example i am registering REPLCAE in postgres dialect like in next code

import org.hibernate.dialect.PostgreSQL9Dialect;
import org.hibernate.dialect.function.StandardSQLFunction;

public class MyPostgreSQL9Dialect extends PostgreSQL9Dialect {

    public MyPostgreSQL9Dialect() {
        super();
        registerFunction("replace", new StandardSQLFunction("replace"));
    }
}

then refer to this custom dialect in your persistence.xml or hibernate.cfg.xml file

0

精彩评论

暂无评论...
验证码 换一张
取 消