Spring Boot pt. 24: Relational Mappings @OneToMany (2/3)

7 months ago
8

SQL Queries:

ALTER TABLE address
ADD COLUMN customer_id BIGINT,
ADD CONSTRAINT fk_customer
FOREIGN KEY (customer_id)
REFERENCES customer (id);

UPDATE address
SET customer_id = (SELECT id FROM customer WHERE id = address.id);

INSERT INTO customer (first_name, last_name) VALUES ('Jane', 'Smith');

INSERT INTO address (street, city, state, customer_id) VALUES
('789 Pine St', 'CityC', 'SC', 1),
('101 Elm St', 'CityD', 'SC', 2);

In today's episode of the No BS Java Spring Boot Guide, we cover relational mappings for relational databases and use the @OneToMany annotation

Loading comments...