Reputation: 13
I have 5 tables MainReg, Person, PersonInfo, Company, CompanyInfo
CREATE TABLE [MainReg] (
[IdMainReg] [uniqueidentifier] NOT NULL,
[PersonalObjectId] [int] NULL,
[OwnerId] [nvarchar](36) NULL,
...)
CREATE TABLE [Person] (
[IdPerson] [uniqueidentifier] NOT NULL,
[PersonInfoId] [nvarchar](36) NULL,
...)
CREATE TABLE [PersonInfo] (
[IdPersonInfo] [uniqueidentifier] NOT NULL,
...)
CREATE TABLE [Company] (
[IdCompany] [uniqueidentifier] NOT NULL,
[CompanyInfoId] [nvarchar] NULL,)
...)
CREATE TABLE [CompanyInfo] (
[IdCompanyInfo] [uniqueidentifier] NOT NULL,
...)
[MainReg.OwnerId] column references row in table [Company] if [MainReg.PersonalObjectId] = 1 and row in table [Person] if [MainReg.PersonalObjectId] = 2.
My question is, how to map this tables using JPA?
Upvotes: 1
Views: 1062
Reputation: 18389
In EclipseLink you can use a @VariableOneToOne relationship to map this.
Otherwise, you may be able to use TABLE_PER_CLASS inheritance for it, or change your data model.
Upvotes: 0
Reputation: 692231
You won't be able to map that in pure JPA. It would need to different foreign keys to be able to map that in JPA: one which would reference Company, and another one which would reference Person.
With Hibernate, you would be able to map that using the Any annotation.
Upvotes: 1