У меня однонаправленные отношения «один к одному» между Passport и PassportType. У меня cascade = CascadeType.ALL указано на отображении.
Почему ограничение внешнего ключа fkh9lgnglfbx8bnvnom6ovyx89 , созданное автоматическим созданием DDL, не имеет ON DELETE CASCADE? Я что-то пропустил?
Я использую Spring Boot 2.2.2.
DDL, созданный в базе данных (отредактировано)
CREATE TABLE public.passport
(
id bigint NOT NULL DEFAULT nextval('passport_id_seq'::regclass),
country_id bigint,
passport_type_id bigint,
CONSTRAINT passport_pkey PRIMARY KEY (id),
CONSTRAINT fkh9lgnglfbx8bnvnom6ovyx89 FOREIGN KEY (passport_type_id)
REFERENCES public.passport_type (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fkqwoht23ddjewoktst0da7j9q7 FOREIGN KEY (country_id)
REFERENCES public.country (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
CREATE TABLE public.passport_type
(
id bigint NOT NULL DEFAULT nextval('passport_type_id_seq'::regclass),
description character varying(255) COLLATE pg_catalog."default",
name character varying(255) COLLATE pg_catalog."default",
CONSTRAINT passport_type_pkey PRIMARY KEY (id)
)
Паспорт. java
@Entity
public class Passport{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(orphanRemoval=true, cascade=CascadeType.ALL)
@JoinColumn(name="country_id")
private Country country;
@OneToOne(orphanRemoval=true, cascade=CascadeType.ALL)
@JoinColumn(name="passport_type_id")
private PassportType passportType;
...
}
PassportType. java
@Entity
public class PassportType{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name; //values: Ordinary, Official, Diplomatic, Emergency, Collective, Family
private String description;
...
}
application.properties
# Database
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://localhost:5432/visa
spring.datasource.username=
spring.datasource.password=
spring.datasource.initialization-mode=always
# JPA
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true