Reputation: 3887
Basically i am trying to write the following query in Hibernate. Please help me to do the same.
SELECT collaboratoruser,GROUP_CONCAT(collaboratorrole SEPARATOR ',') FROM tbl_conceptcollections_collaborator WHERE collectionid = incollectionid GROUP BY collaboratoruser;
I cannot use SQL Query and i want to use only HQL. Any help appreciated.
Upvotes: 3
Views: 8186
Reputation: 558
You can register Group_Concat function in hibernate. For example Create a class First
public class RegisterSqlFunction extends MySQLDialect {
public RegisterSqlFunction() {
super();
registerFunction("group_concat", new StandardSQLFunction("group_concat", StandardBasicTypes.STRING));
}
}
Second Register in hibernate Propeties
properties.put("hibernate.dialect", "com.app.web.config.sql.RegisterSqlFunction");
and then you can use it.
Upvotes: 0
Reputation: 68
Frank answer is No.
Why so ?
Hibernate supports only common function/syntax used in multiple database's. Moreover, There isn't any group_concat function in MySQL Server and probably could be the same for other database as well.
Solution:
You have to execute it as Native SQL Query only.
Upvotes: 5