0

I have two tables in my DB: Customers and Companies.

Mapping for Customer:

<class name="CustomerModel" table="CUSTOMERS" mutable="false">

    <cache usage="transactional"/>

    <id name="id" type="java.lang.Long">
        <column name="ID" precision="19" scale="0"/>
        <generator class="assigned"/>
    </id>

    <many-to-one name="company" not-null="true" column="CUSTOMER_COMP_ID" class="CompanyModel" />

    <property name="type"  type="CustomerType">
        <column name="TYPE"/>
    </property>

    <property name="fullName" type="string">
        <column name="FULL_NAME"/>
    </property> 

</class>

TYPE column/property can contains two values: PERSON, COMPANY

And for Company:

<class name="CompanyModel" table="COMPANIES" mutable="false">

    <cache usage="transactional"/>

    <id name="id" type="long">
        <column name="ID" precision="19" scale="0" />
    </id>

    <property name="name" type="string">
        <column name="NAME"/>
    </property>

</class>

I want to create formula for property fullName in CustomerModel which:

  • when type = 'PERSON' then fullName = fullName (do not change it)
  • when type = 'COPMANY' then funnName = company.name

How to create such formula?

Wicia
  • 575
  • 3
  • 9
  • 28

0 Answers0