Hibernate Union 替代方案 [英] Hibernate Union alternatives

查看:33
本文介绍了Hibernate Union 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用休眠实现联合查询有哪些替代方法?我知道 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 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆