A
A
Alexey Savchuk2018-06-06 16:07:33
Java
Alexey Savchuk, 2018-06-06 16:07:33

How to stop propagation of cascading operations in Hibernate?

How can Hibernate stop propagating cascading operations to child objects?
Example:

public class EmployeeEntity {
  @OneToMany(
        cascade = CascadeType.ALL
  )
  @JoinColumn(name = "employee_id", referencedColumnName = "employee_id")
  private Set<EmployeeHotelPermissionsEntity> hotelsPermissions = new HashSet<>();
}

public class EmployeeHotelPermissionsEntity {
  @ManyToOne()
  @JoinColumn(name = "hotel_id")
  // <--- остановить cascade = CascadeType.ALL здесь --->
  private HotelEntity hotel;
}

I want to make sure that when saving an EmployeeEntity object, HotelEntity from EmployeeHotelPermissionsEntity is not saved.
UPD: it's all about @IdClass which was set for EmployeeHotelPermissionsEntity and contained HotelEntity.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-06-06
@EreminD

well, here's cascade = CascadeType.ALL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question