如何防止Hibernate公式注释在保留字之前添加表名? [英] How to prevent Hibernate formula annotation of adding table name before reserved words?
问题描述
我的班级映射如下:
@Entity
public class Order {
private String formulatedProp;
@Formula(value="(SELECT ',' + coalesce(a.description,a.code)
FROM another_table a
WHERE a.order_id=id FOR XML PATH(''))")
public String getFormulatedProp() {
return formulatedProp;
}
}
单独执行公式的SQL查询会很好.但是,当Hibernate生成查询以获取订单时,它会将表的别名附加到FOR
和XML
单词.因此,它尝试执行
The formula's SQL query is fine when executing on its own. But when Hibernate generates the query to fetch an Order, it appends table's alias to FOR
and XML
words. So it tries to execute a query like
SELECT ',' + coalesce(a.description,a.code)
FROM another_table a
WHERE a.order_id=order0_.id order0_.FOR order0_.XML PATH('')
这显然是错误的.我该怎么做?
环境: Hibernate 3.6 , SQL-Server 2008
Which is obviously wrong. How can I make this work?
Environment: Hibernate 3.6, SQL-Server 2008
P.S.我知道可以使用自定义方言来解决,但我不希望朝这个方向发展.
推荐答案
您可以使用我在此问题中编写的相同解决方案: https://stackoverflow.com/a/26907699/825061
You can use the same solution that I have written in this question: https://stackoverflow.com/a/26907699/825061
简短的答案是扩展您使用的休眠方言类并注册新的保留字.
The short answer is extend the hibernate dialect class that you use and register your new reserved words.
这篇关于如何防止Hibernate公式注释在保留字之前添加表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!