[hibernate-dev] SQL union is not working in SQL query for property attribute "formula" in hibernate mapping

Steve Ebersole steve at hibernate.org
Fri Oct 19 07:38:49 EDT 2007


On Thursday 11 October 2007 06:03:04 am Vadim Gindin wrote:
> Hello, hibernate-dev!
>
> I've found following problem. I need, that my persistent entity Reference
> would have calculated field "title". It is a title of object, that my
> Reference entity refers to. My Reference entity also would have identifier
> of this object. This object can be an entity of classes in the different
> classes hierarhies. I want to calculate title field of Reference as object
> title. So, I'm writing this mapping:
>
> <class name="Reference" ..>
>     <property name="objectId" ../>
>   <property name="title" formula="(select obj1.title from Table1 obj1 where
> obj1.Id=objectId
>                                           union
>                                    select obj2.title from Table2 obj2 where
> obj2.Id=objectId)"/>
> </class>
>
> I know, that this query in my case will return only one value.
>
> So, When hibernate is trying to load my Reference entity, it constructs
> wrong SQL query (something like this):
>
> select
>   ...,
>   objectId,
>    (select obj1.title from Table1 obj1 where obj1.Id=objectId
>         reference0_.union
>              select obj2.title from Table2 obj2 where obj2.Id=objectId)
> from ReferenceTable reference0_
> ...
>
> I think it is a bug. Could anybody comment my situation?
>
> P.S. My execution environment: Hibernate-Version: 3.2.5.ga
>
> Sincerely yours, Vadim Gindin
> mailto: vgindin at gmail.com

Have you tried searching Jira?  

Rhetoric question, as I know you have not...  this has already been reported 
and fixed.



More information about the hibernate-dev mailing list