Spring Boot pt. 25: Relational Mappings @ManyToMany (3/3)

25 days ago
1

SQL Queries:
CREATE TABLE customer_address (
customer_id BIGINT,
address_id BIGINT,
PRIMARY KEY (customer_id, address_id),
FOREIGN KEY (customer_id) REFERENCES customer(id),
FOREIGN KEY (address_id) REFERENCES address(id)
);

INSERT INTO customer_address (customer_id, address_id)
SELECT customer_id, id as address_id
FROM address;

ALTER TABLE address
DROP FOREIGN KEY fk_customer;

ALTER TABLE address
DROP COLUMN customer_id;

In today's No BS Guide to Java Spring Boot, we finish Relational Mappings by using the @ManyToMany annotation, creating a Junction table, upholding the previous relationship of @OneToMany. We also use @JSONIGNORE to deal with a circle reference.

LinkTree:
https://linktr.ee/peachezprogramming

Loading comments...