Hooking into Hibernate's query generation

喜夏-厌秋 提交于 2019-12-07 14:48:13

问题


I would like to implement virtual views with a preprocessor. A simple example:

HQL before:

FROM PublishedArticle a

Effective HQL after:

FROM Article a
WHERE a.published = true

Essentially I need a way to process queries before they get executed (instead of creating views on-the-fly which would have a high cost).


回答1:


You can use a StatementInspector to completely rewrite the SQL to suit your needs.

For further reading: How I can configure StatementInspector in Hibernate?




回答2:


Couldn't you do that with a Hibernate filter? Of course for things more complex than WHERE it wouldn't work: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/filters.html



来源:https://stackoverflow.com/questions/22435631/hooking-into-hibernates-query-generation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!