问题
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