Skip to main content
Jump to: navigation, search

Talk:EclipseLink/Examples/REST/GettingStarted/DatabaseModel

Revision as of 04:27, 3 August 2015 by Petr.hariprasad.gmail.com (Talk | contribs) (Mix primary and foreign key in one is not good design practice for beginners.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I suggest to change entity Address defined as:

ADDRESSS Table

CREATE TABLE "ADDRESS"

( "ID" NUMBER NOT NULL ENABLE, 
"STREET" VARCHAR2(50), 
"CITY" VARCHAR2(50), 
CONSTRAINT "ADDRESS_PK" PRIMARY KEY ("ID") ENABLE, 
CONSTRAINT "ADDRESS_FK" FOREIGN KEY ("ID")
REFERENCES "CUSTOMER" ("ID") ENABLE
)

/


to

ADDRESSS Table

CREATE TABLE "ADDRESS"

( "ID" NUMBER NOT NULL ENABLE, 
"STREET" VARCHAR2(50), 
"CITY" VARCHAR2(50), 
"CUSTOMER_ID" NUMBER,
CONSTRAINT "ADDRESS_PK" PRIMARY KEY ("ID") ENABLE, 
CONSTRAINT "ADDRESS_FK" FOREIGN KEY ("CUSTOMER_ID")
REFERENCES "CUSTOMER" ("ID") ENABLE
)

/

And change further code as well according this change.

Reason: Eclipse (Luna) doesn't generate model classes properly and this construction causes fail in query. To merge primary and foreign key together is not so much common construction and it not appropriate for many further software. To treat OneToOne relation is much more appropriate on the programming side rather than in DB structure.

Back to the top