Hi, forum.
I'm trying to use one-to-one mapping with formula. I have a domain class, within domain there has a list of OU object, but only one OU is root OU which parent ou is null. I want to have root OU in my domain object. So, I define them as:
<class name="Domain" table="DOMAIN">
<id name="id" type="long" column="id">
<generator class="native" />
</id>
<one-to-one name="rootOu" class="OrgUnit" property-ref="rootOu">
<formula>DOMAINID"</foruma>
<formula>'1'</formula>
</one-to-one>
</class>
<class name="OrgUnit" tablel="OrgUnit">
<id name="id" type="long" column="id">
<generator class="native" />
</id>
<properties name="rootOu">
<many-to-one name="domain" class="Domain" fetch="select">
<column name="DOMAINID" not-null="true" />
</many-to-one>
<property name="nullParent" type="boolean">
<formula>case when PARENTID is null then 1 else 0 end</formula>
</property>
</properties>
</class>
It generate currect SQL statement to select domain object, but when load rootOu, the select statement generated is wrong.
for domain object:
select
domain0_.ID as ID1_0_0_,
'1' as formula0_0_
from TEST.DOMAIN domain0_
where domain0_.ID=?
for rootOu:
select
orgunit0_.ID as ID1_2_0_,
orgunit0_.DOMAINID as DOMAINID2_2_0_,
orgunit0_.PARENTID as PARENTID3_2_0_,
case when orgunit0_.PARENTID is null then 1 else 0 end as formula1_0_
from TEST.ORGUNIT orgunit0_
where orgunit0_.DOMAINID=?
and orgunit0_.null=?
As you can see, last line should be: "and orgunit0_.formula1_0_=?", but it generate "and orgunit0_.null=?".
I tried to use "many-to-one" with formula as well. but same thing. It looks like it not work with both side formula?
Am I doing something wrong? Or it's a bug?
Thanks a lot
Noodle
|