Hibernate Union的替代品 [英] Hibernate Union alternatives

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

问题描述

使用hibernate实现联合查询有哪些选择?我知道hibernate目前不支持union查询,现在我看到做一个union的唯一方法就是使用一个view table。

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.

纯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天全站免登陆