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

后端 未结 1 812
终归单人心
终归单人心 2020-12-28 16:48

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)

相关标签:
1条回答
  • 2020-12-28 17:28

    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")
      )}
    )
    
    0 讨论(0)
提交回复
热议问题