不好意思,没有详细说。我用Hibernate的HQL想合并两个查询,但是Hibernate不支持使用union不知有没有人遇过这样的问题,怎么解决他。

解决方案 »

  1.   

    HQL可以实现union查询,请参见hibernate文档第10.3节上的说明
      

  2.   

    hibernate文档第10.3节好像没有关于union的内容吧。10.3. Considering object identity
    The application may concurrently access the same persistent state in two different units-of-work. However, an instance of a persistent class is never shared between two Session instances. Hence there are two different notions of identity: Database Identity
    foo.getId().equals( bar.getId() ) JVM Identity
    foo==bar Then for objects attached to a particular Session, the two notions are equivalent. However, while the application might concurrently access the "same" (persistent identity) business object in two different sessions, the two instances will actually be "different" (JVM identity). This approach leaves Hibernate and the database to worry about concurrency. The application never needs to synchronize on any business object, as long as it sticks to a single thread per Session or object identity (within a Session the application may safely use == to compare objects). 
      

  3.   

    那有没有什么方法可以实现union的效果呢?