title: Spring Hibernate delete object
body: <p>I try to remove object from entity by using 'delete' from repository but something doesn't work.</p>
  
  <pre><code>@Entity
  public class Director implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      private Long id;
  
      @Column(length = 15)
      private String name;
  
      @Column(length = 40)
      private String surname;
  
      @Column(length = 40,unique=true, nullable=false)
      private String email;
  
      @Column(length = 12)
      private String phone;
  
      @OneToOne
      private School school;
  
      public School getSchool() {
          return school;
      }
  
      public void setSchool(School school) {
          this.school = school;
      }
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getSurname() {
          return surname;
      }
  
      public void setSurname(String surname) {
          this.surname = surname;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getPhone() {
          return phone;
      }
  
      public void setPhone(String phone) {
          this.phone = phone;
      }
  }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>@Repository
  public interface DirectorRepository extends CrudRepository&lt;Director, Long&gt; {
  
      Director findOneByEmail(String email);
  
  }
  </code></pre>
  
  <p>Method from Controller:</p>
  
  <pre><code>@RequestMapping(value = "deleteDirector", method = RequestMethod.POST)
      public String delpost(@ModelAttribute Director director) {
  
          try {
              directorRepository.delete(director.getId());
              return "deleteDirectorSuccess-view";
          }
          catch(Exception e){
  
          }
          return "deleteDirectorError-view";
      }
  </code></pre>
  
  <p>I don't know what happens there because it returns <code>deleteDirectorSuccess-view</code> but doesn't delete this object from database (Im sure that id is correct, I tried put <code>directorRepository.delete(ID_FROM_DATABASE_AS_LONG);</code> but there is the same problem.
  If I put script in database like:</p>
  
  <pre><code>DELETE FROM public.director
   WHERE id=ID_FROM_DATABASE;
  </code></pre>
  
  <p>it works, another method in controller where I save object to database by:</p>
  
  <pre><code>directorRepository.save(director);
  </code></pre>
  
  <p>works perfectly too.</p>
  
  <p>I have no idea how to check why it's wrong and how to solve my problem.</p>