Hi,
I am new to Hibernate, and would like to know how a java model class can be mapped to different database tables in Hibernate.
I have the following scenario:
I have a java class A, which is used in different contexts as below.
In certain cases, A will appear as aggregation composition to class B.
i.e., B -> A*
and in certain cases, A will appear as aggregation composition to class C.
i.e., C -> A*
In this case, I have a set of A objects under B and a set of different A objects under B as well.
As I understand from Hibernate Tutorials, I need to have a OR mapping from A to a Database Table, B to a DB table, and C to a DB table. Hence I'll have to create DB mapping as below:
A -> TABLE_A
B -> TABLE_B
C -> TABLE_C
But this is not what I want, as this breaks my business model of tables.
I would like the information to be stored in the following tables;
B -> TABLE_B
C -> TABLE_C
A that's aggregated under B class should be stored in TABLE_A1
and A that's aggregated under C class should be stored in TABLE_A2
Can you let me know if it's possible to specify this mapping through Hibernate?
I really appreciate any response.
Thanks
--
Anish.
|