使用休眠实现联合查询有哪些替代方法?我知道 hibernate 目前不支持联合查询,现在我看到的唯一方法是使用视图表.
What alternatives do I have to implement a union query using hibernate? I know hibernate does not support union queries at the moment, right now the only way I see to make a union is to use a view table.
另一种选择是使用普通的 jdbc,但这样我会丢失所有示例/标准查询的好处,以及 hibernate 对表/列执行的 hibernate 映射验证.
The other option is to use plain jdbc, but this way I would loose all my example/criteria queries goodies, as well as the hibernate mapping validation that hibernate performs against the tables/columns.
推荐答案使用 VIEW.可以使用实体名称将相同的类映射到不同的表/视图,因此您甚至不会有太多重复.在那里,这样做,工作正常.
Use VIEW. The same classes can be mapped to different tables/views using entity name, so you won't even have much of a duplication. Being there, done that, works OK.
Plain JDBC 还有一个隐藏的问题:它不知道 Hibernate 会话缓存,所以如果某些东西被缓存到事务结束并且没有从 Hibernate 会话中刷新,JDBC 查询将找不到它.有时可能会很令人费解.
Plain JDBC has another hidden problem: it's unaware of Hibernate session cache, so if something got cached till the end of the transaction and not flushed from Hibernate session, JDBC query won't find it. Could be very puzzling sometimes.
更多推荐
Hibernate Union 替代方案
发布评论