I have two tables. Site
have a lot of Sector
s.
When I try to edit the list of sectors of a site, for example I have 3 sectors initially, so I delete one sector and I update the site. in the database are three sectors of the Site.
Is it possible that the sectors are automatically deleted when I update a site? or I have to compare one to one?
Thanks.
Site entity
public class Site {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
....
@OneToMany(fetch = FetchType.EAGER, mappedBy = "site", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Sector> sectores;
}
Sector entity
public class Sector {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idGenerator")
@SequenceGenerator(name="idGenerator", sequenceName="SECTOR_SEQ")
@Column(name = "IDSECT")
private Integer id;
@Column(name = "NOMBRE")
private String nombre;
@ManyToOne
@JoinColumn(name = "IDSITE")
private Site site;
}
log
08:17:55,096 INFO [stdout] (http--0.0.0.0-8080-2) Hibernate: update SITE set SITIO_CODIGO=?, SITIO_NOMBRE=? where ID=?
08:17:55,116 INFO [stdout] (http--0.0.0.0-8080-2) Hibernate: update SECTOR set NOMBRE=?, IDSITIO=? where IDSECT=?