gpt4 book ai didi

java - Hibernate:如何使用 CONCAT 和 GROUP_CONCAT

转载 作者:IT老高 更新时间:2023-10-29 00:21:54 29 4
gpt4 key购买 nike

如何在 HQL 查询中使用 CONCAT()GROUP_CONCAT()

最佳答案

关于 concat:它的工作方式与它在 MySQL 中的工作方式完全相同(它连接字符串,它不是聚合函数)。

您可以将 group_concat 作为 sql 函数添加到您的配置中。这样您就可以假设底层数据库知道此函数,并将您的程序绑定(bind)到 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()));

您还指出该函数的输出是一个字符串。没有这个,当你 group_concat 数字字段时,Hibernate 将假定结果也是数字并崩溃。

关于java - Hibernate:如何使用 CONCAT 和 GROUP_CONCAT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4955580/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com