# Property with formula: how to inject schema?

**URL:** <https://discourse.hibernate.org/t/property-with-formula-how-to-inject-schema/5018>\
**Category:** Hibernate ORM\
**Created:** [February 4, 2021, 11:41am UTC](https://discourse.hibernate.org/t/property-with-formula-how-to-inject-schema/5018 "2021-02-04T11:41:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@Tomas](https://discourse.hibernate.org/u/Tomas)\
**Post date:** [February 4, 2021, 11:41am UTC](https://discourse.hibernate.org/t/property-with-formula-how-to-inject-schema/5018/1 "2021-02-04T11:41:56Z")

</div>

Hi,  
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 o.id = 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:

```auto
<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,  
Tomas

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [February 8, 2021, 8:08am UTC](https://discourse.hibernate.org/t/property-with-formula-how-to-inject-schema/5018/2 "2021-02-08T08:08:28Z")

</div>

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

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