在一个表中查询到一组数据将相同教师id的项按照班级id合并对于professCourse中的数据进行合并。
在mysql语句用group_concat()直接执行可以实现 select startTime,EndTime,group_concat(dictionaryLeafValue),classesId ,professCourse from Teacherclassinfobyacc group by classesId
然而在ssh框架中用到String hql =“ ”;却无法执行,报错将group_concat(dictionaryLeafValue)看成是一个字段,不识别group_concat(),函数。
hibernate不能实现的数据库函数怎么使用呢
查询网上,有人改变了hibernate的方言,可以解决。但我并未成功。方法如下:
重写hibernate方言
package com.ayu.hibernate.test;
import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.StandardSQLFunction;
public class AyuMySQLDialect extends MySQLDialect {
protected void registerVarcharTypes() {
registerFunction("group_concat", new StandardSQLFunction("group_concat",Hibernate.STRING));
}
}
<prop key="hibernate.dialect">com.ayu.hibernate.test.AyuMySQLDialect</prop>
hql语句:select f.fid,group_concat(f.fname) from Fund f group by f.user.uid
未解决我的问题于是navicat中创建一个视图在视图中将条件写入。得到一个合并的视图。操作查询该视图即可完成。