tags:

views:

391

answers:

1

I have the REGION table:

REG {
    id number,
    dateCreation Date
  }

I have a LOCALE table:

LOCALE {
     locale String
  }

I have a REGION_DESCRIPTION table:

REGION_DESCRIPTION {
     locale String,
     regId number,
     description
  }

REGION_DESCRIPTION has a composite key: locale is a foreign key pointing to the LOCALE table. And regId points to the REGION table.

I would like to map this to my Region java class:

private List<RegionDescription> descriptions;

I tried different approache in JPA. But I cannot get the mapping to work. Any suggestions?

A: 

You have a case of a join table (REGION_DESCRIPTION) becoming an entity by carrying its own attributes. I would suggest the following:

  1. define RegionDescription as a complete entity with composite primary key class, see example;

  2. define 2 many-to-one relationships in RegionDescription: RegionDescription to Region and RegionDescription to Locale.

  3. alternatively or in addition define one-to-many relationship in Region to map RegionDescription's the way you specified above.

grigory