When deleting a record with MySQL workbench, javax.persistence.EntityNotFoundException occurs

environment

Spring Boot 2.4.0 java 1.8 thymeleaf 3.0.11 Spring Security 2.4.0 MySQL 8.0.22

phenomenon

I deleted the record that I thought "I don't want" in MySQL Workbench. You deleted it with Delete row.

Then I couldn't log in to the system.

It's a record that has nothing to do with the login I was trying to separate.

It's okay if you put it back again, but since there is AutoIncrement,

  1. Remove AutoIncrement
  2. Insert to specify id
  3. Turn on Auto Increment

You can't get it back unless you do something annoying.

I did it before, but I didn't know the solution and couldn't move forward, so for the time being it was annoying, but I did the above method.

But I thought it was unnecessary afterwards, so when I tried to delete it, "See you again ..."

There may be more, so I did a little research.

solution

https://stackoverflow.com/questions/46612968/hibernate-unable-to-find-entity-with-id I referred to this.

@NotFound(action = NotFoundAction.IGNORE)

Apparently I should add this.

where? !!

@ManyToOne (below)

Example

@Entity
Supplier {
  //Field omitted
}

@Entity
Wedding {
  //Field omitted
  @ManyToOne //← It looks like I'm looking for a record that I erased ...
  private Supplier supplier;
}

After change

@Entity
Wedding {
  //Field omitted
  @ManyToOne
  @NotFound(action = NotFoundAction.IGNORE) //← Thanks to this, it seems to ignore me
  private Supplier supplier;
}

Cause

Still do not know. Why are you looking for the ID of the record you should have deleted? Do you remember it? Where is it stored?

I don't understand.

But it may have been saved somewhere. Is it Hibernate? ??

I don't really understand Spring Boot, but I want to understand it while using it! !!

For the time being, I hope it will be helpful for those who cannot move forward due to the same error.

Recommended Posts

When deleting a record with MySQL workbench, javax.persistence.EntityNotFoundException occurs
What to do when a javax.el.PropertyNotWritableException occurs
Create a MySQL environment with Docker from 0-> 1
When calling API with java, javax.net.ssl.SSLHandshakeException occurs
A reminder when an aapt.exe error occurs
Create a simple bulletin board with Java + MySQL
Be careful when deleting multiple elements from an array etc. with a for statement