Property with formula: how to inject schema?

I have property mapped to other’s table column value in hbm.xml file:

<property name="OwnerUUID" formula="(select o.UUID from PERSISTABLE o where = OWNER_ID)" type="string" />

This perfectly works fine until non default schema is used as result this query fails to evaluate value.
Alternative I could use additional mapping to an object but using this object pulls big structure, thus this needs to be avoided. However, I’ve got parent object class without additional mappings which I could use but it does not resolve correctly since such column already mapped, thus it does not return me an object.

Here is fallowing mappings:

<many-to-one name="Owner"     column="OWNER_ID"       foreign-key="FK_AUDITTRAIL_OWNER"     not-null="true"              index="IDX_AUDITTRAIL_OWNER"/>
<many-to-one name="OwnerOnly" column="OWNER_ID"       property-ref="ID"    insert="false" update="false" />

So I see only two solutions which I cannot make to work since:

  • Was unable to find solution extending property formula with additional table Schema. Found suggestion to modify the schema dynamically but did not researched more.
  • Removing property with formula and adding OwnerOnly mapping results in null value while Owner mapping is populated fine
  • Unable to use Owner property since it pulls too much data, but it is used only for setting value (aka store OWNER_ID value), thus I cannot drop this mapping.

Please provide suggestion how I could resolve fixing formula value with injecting schema name (for example: testuser.PERSISTABLE) without hardcoding schema or create additional duplicating Owner mapping as OwnerOnly which contains only linked table.

Thanks in advance,

I think you can use {alias} in the mapping i.e. use

<property name="OwnerUUID" formula="(select o.UUID from PERSISTABLE o where = {alias}.OWNER_ID)" type="string" />