Java – Hibernate: how to use concat and group_ CONCAT

How to use concat() and group in HQL queries_ CONCAT()?

Solution

About concat: its working principle is the same as that in MySQL (it connects strings, it is not an aggregate function)

You can group_ Concat is added to the configuration as an SQL function In this way, you can assume that the underlying database knows this function and bind the program to MySQL

import org.hibernate.cfg.Configuration; 
import org.hibernate.dialect.function.StandardsqlFunction;
import org.hibernate.type.StringType;

// ...
myConf.addsqlFunction("group_concat",new StandardsqlFunction("group_concat",new StringType()));

You will also point out that the output of the function is a string Without this, when you_ Concat's numeric field hibernate will assume that the result is also numeric and crashes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>