0

previously , this is how i map my "Activity" table. This table is storing CONTACT_ID and ACCOUNT_ID which link to Account and Contact table. enter image description here

in this way

<many-to-one
    name="accountObj"
    class="my.com.miramax.crm.account.db.Account"
    not-null="false"
    not-found="ignore"
    insert="false"
    update="false"
    column="ACCOUNT_ID"
/>

Now i have a table like below enter image description here

this table doesn't store the ACCOUNT_ID and CONTACT_ID, but it separated into "Table_REF" and "REF_ID". For example , TABLE_REF = "Account" and REF_ID = 239 is same as the Account_ID = 239 in the Account table.

Can anyone tell me how do i map this table, so that i can differentiate them and use it in the DAO for searching ?

Please help me. Thanks in advance.

user998405
  • 1,329
  • 5
  • 41
  • 84

2 Answers2

0

You can try the following mapping --- This will populate it based on whether ID exists in corresponding tables. You can use the following query to load the data properly.

"from Activity activity left outer join activity.account ac with tableref='Account' left outer join activity.contact con with tableref='Contact'"

------------

<many-to-one name="account" 
column="REF_ID"
insert="false"
update="false" 
lazy="no-proxy"
not-found="ignore"
>
</many-to-one>

<many-to-one name="contact" 
column="REF_ID"
insert="false"
update="false"
lazy="no-proxy"
not-found="ignore"
>
</many-to-one>
Ram Reddy
  • 123
  • 6
  • i'm new to hibernate , i cant see anywhere to apply the query in my hbm.xml, can you please tell me more details ? Thanks a lot. – user998405 May 07 '12 at 09:48
0

To me, it sounds like a typical case for <any>:

<any name="referenceObj" id-type="long" meta-type="string">
    <meta-value value="Account" class="my.com.miramax.crm.account.db.Account"/>
    <meta-value value="Contact" class="..."/>
    <column name="TABLE_REF"/>
    <column name="REF_ID"/>
</any>

See the reference documentation.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • thanks a lot, may i know how do i apply the referenceObj create by in DAO ? i want to do a searching that will filter the Account table. Usually i can do like this in DAO - "criteria.createAlias(CostCentre.PROP_CONTACT_OBJ, CostCentre.PROP_CONTACT_OBJ, Criteria.LEFT_JOIN);" – user998405 May 07 '12 at 09:53