kauedb
kauedb

Reputation: 233

Is possible map a single entity with multiple tables using JPA?

I got a legacy database domain I can't change but it was possible conceive a domain entity to address my problema.

Legacy Tables: TABLE1(ID,VALUE) TABLE2(ID,DATE) TABLE3(ID,DESCRIPTION)

Domain: NewConceptDomain { int value; Date date; String description; }

How can I map new NewConceptDomain using JPA?

Upvotes: 19

Views: 29340

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18413

Use @SecondaryTable (http://en.wikibooks.org/wiki/Java_Persistence/Tables#Multiple_tables)

@Entity
@Table(name="TABLE1")
@SecondaryTables({
  @SecondaryTable(name="TABLE2",
    pkJoinColumns = @PrimaryKeyJoinColumn(name="ID", referencedColumnName="ID")
  ),
  @SecondaryTable(name="TABLE3",
    pkJoinColumns = @PrimaryKeyJoinColumn(name="ID", referencedColumnName="ID")
  )}
)

Upvotes: 45

Related Questions