content: package com.adamzareba.spring.security.oauth2.model;
  
  import com.fasterxml.jackson.annotation.JsonBackReference;
  import com.fasterxml.jackson.annotation.JsonManagedReference;
  
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.ManyToOne;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  
  import lombok.Getter;
  import lombok.Setter;
  
  @Entity
  @Table(name = "DEPARTMENT")
  @Getter
  @Setter
  public class Department implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "ID", updatable = false, nullable = false)
      private Long id = null;
  
      @Column(name = "NAME", nullable = false)
      private String name;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "department", fetch = FetchType.LAZY, orphanRemoval = true)
      @JsonManagedReference
      private Set<Employee> employees = new HashSet<>();
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "department", fetch = FetchType.LAZY, orphanRemoval = true)
      @JsonManagedReference
      private Set<Office> offices = new HashSet<>();
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JsonBackReference
      private Company company;
  
      public void setEmployees(Set<Employee> employees) {
          this.employees.clear();
          if (employees != null) {
              this.employees.addAll(employees);
          }
      }
  
      public void setOffices(Set<Office> offices) {
          this.offices.clear();
          if (offices != null) {
              this.offices.addAll(offices);
          }
      }
  }
  