I need to map two tables to a single class, having trouble figuring this out. One table is ROOMS, the other is TRAINERS.
The ROOMS table:
OOC_UNIT
To map a single class to two (or more) separate tables you need to use a @SecondaryTable annotation:
@Table(name="ROOMS")
@SecondaryTable(name="TRAINERS", pkJoinColumns={
@PrimaryKeyJoinColumn(name="TRSC_OOC_UNIT_ID", referencedColumnName="OOC_UNIT_ID"),
@PrimaryKeyJoinColumn(name="TRSC_OOC_START_DT", referencedColumnName="OOC_START_DT"),
@PrimaryKeyJoinColumn(name="TRSC_OOC_START_TM", referencedColumnName="OOC_START_TM")
})
public class MyMergedEntity {
You'll then need to annotate each individual property mapped to TRAINERS table with @Column(table="TRAINERS") to specify which table it belongs to. If you're using XML mappings instead, all of the above can be done via join element.
All that said, it seems to me that your two tables are rather different in nature and should not be mapped to a single class (especially since you've said you've already mapped ROOMS elsewhere). Perhaps you should map your Trainer as ManyToOne association instead.