About Question enthuware.oce-jpad.v6.2.431 :
Posted: Wed Jan 06, 2016 6:48 am
Example from the explanation is not complete. According to comment in the first option both columns should be UNIQUE . First is primary key of the join table thus it will be unique by definition. But the second one is defined by partially default @JoinColumn, where "unique" is false. So, table in db will be definied as following:
To make it better unique attribute has to be set to true:
Second column will not be unique and the same additional data can be associated with two different Account.CREATE TABLE acct_acctdet_jointable
(
act_details_id integer,
acct_id integer NOT NULL,
CONSTRAINT acct_acctdet_jointable_pkey PRIMARY KEY (acct_id),
CONSTRAINT fk949un3kgn8s2vbqb0sff1sto8 FOREIGN KEY (acct_id)
REFERENCES account (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fkn66tbtylqpyf93leaxe4nk2p8 FOREIGN KEY (act_details_id)
REFERENCES account_details (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
To make it better unique attribute has to be set to true:
After that table in db looks:@JoinTable(name = "ACCT_ACCTDET_JOINTABLE",
joinColumns = @JoinColumn(name = "ACCT_ID"),
inverseJoinColumns = @JoinColumn(name = "ACT_DETAILS_ID", unique = true))
CREATE TABLE acct_acctdet_jointable
(
act_details_id integer,
acct_id integer NOT NULL,
CONSTRAINT acct_acctdet_jointable_pkey PRIMARY KEY (acct_id),
CONSTRAINT fk949un3kgn8s2vbqb0sff1sto8 FOREIGN KEY (acct_id)
REFERENCES account (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fkn66tbtylqpyf93leaxe4nk2p8 FOREIGN KEY (act_details_id)
REFERENCES account_details (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT uk_9h1b7pr1yblcjd8jw2tx3wieg UNIQUE (act_details_id)
)