本文介绍了SEPARATOR关键字在Hibernate Formula中不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的Hibernate forumla query,我可以在mysql workbanch中执行。

I have following Hibernate forumla query, which I am able to execute in mysql workbanch.

select group_concat(distinct t.column_1_name SEPARATOR ', ') from table_name t and t.fk_record_id = record_id



时,column_1_name SEPARATOR',' ,hibernate将父表附加到SEPRATOR关键字,如下面的查询所示。

While executing this query with Hibernate, hibernate is appending parent table to the SEPRATOR key word as shown in the below query.

select group_concat(distinct t.column_1_name parent_table.SEPARATOR ', ') from table_name t and t.fk_record_id = record_id

这里hibernate没有处理SEPRATOR作为关键字。任何人都有这个想法吗?

Here hibernate is not treating SEPRATOR as keyword. Anyone has any idea about this?

推荐答案

您可以将 SEPARATOR 添加为关键词。实现您自己的 DialectResolver 并将小写字母添加到生成的方言中:

You can add SEPARATOR as keyword. Implement your own DialectResolver and add the keyword in lower case to the resulting dialect:

public class MyDialectResolver extends StandardDialectResolver {

  protected Dialect resolveDialectInternal(DatabaseMetaData metaData) throws SQLException {
    Dialect dialect = super.resolveDialectInternal(metaData);
    dialect.getKeywords().add("separator");
    return dialect;
  }

}

然后你必须告诉Hibernate使用你的方言解析器。例如,在JPA中,您可以在persistence.xml中执行此操作:

You will then have to tell Hibernate to use your dialect resolver. For example in JPA you can do this in your persistence.xml:

<persistence>
  <persistence-unit>
    ...
    <property name="hibernate.dialect_resolvers" value="mypackage.MyDialectResolver"/>
  </persistence-unit>
</persistence>

顺便说一句:同样的情况也适用于其他方言的聚合功能。例如在Oracle中缺少 WITHIN 关键字。

Btw: The same applies to aggregating functions in other dialects. For example in Oracle the WITHIN keyword is missing.

这篇关于SEPARATOR关键字在Hibernate Formula中不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:36