----------- -----------
| Table 1 | | Table 2 |
| ----- | | ----- |
| ID | | ID |
| NAME | | T1_ID |
| . | | . |
| . | | . |
----------- -----------
ONE T1.ID ---<- MANY T2.T1_ID
I have a table relationship as depicted above. I want to include only the NAME field from Table 1 into the entity that I'd like to create for Table 2 (because Table 1 has way too many fields that I don't want).
@SecondaryTable
solution proposed here does not work for this scenario because of two reasons:
- It requires one-to-one relationship between both the tables
- It requires the foreign key(T1_ID) to serve as the primary key of Table 2 (from what I understand of this exception - org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non-primary key)
Kindly suggest if there's a way to avoid pulling in the heavier Table 1 entity into Table 2 entity. Otherwise, the only shortcut I see here is to persist the NAME field in Table 2.