Good morning, I'm new to Hibernate and I have a doubt with cascading erasures.
I want to know if it is possible that the cascade deletion is made based on the value of a field, I explain.
I have the entities Country (id, name) and Province (id, name, country, enabled), with a relation 0 an, by which there could be provinces that having an associated country, said country is possible that it did not exist, in which case, the value of enabled for the Province entity would be "false".
The fact is that I want to know if it is possible to define the entity in some way that when the deletion of a country is made, just delete the provinces that having that country associated, have the value of enabled to "true". With what I know up to now, it eliminates all the provinces.
Entity Country:
@Entity
@Table(name = "Pais")
public class PaisEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private Stringnombre;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
@JoinColumn(name = "pais")
private List<ProvinciaEntity> listaProvincias;
Province Entity
@Entity
@Table(name = "Provincia")
public class ProvinciaEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private String nombre;
@Column
private Boolean habilitado;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "pais")
private PaisEntity pais;
I do not know if I should change any annotation or add any attribute in the existing annotations.
Greetings and thanks for the help.