riverrevir / searchPID

0 stars 1 forks source link

#1 JPA entity error #1

Open riverrevir opened 2 years ago

riverrevir commented 2 years ago
  1. java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
  2. Failed to create query for method public abstract java.util.Optional

데이터베이스 엔티티 생성 문제 발생

riverrevir commented 2 years ago

1,2 오류는 엔티티에서 쿼리에 적용되지 않은 필드명을 작성하여서 오류가 났다. 가능하면 JPA로 필드를 만들 때 _연속된 언더바는 피하는게 좋을 것 같다. _를 빼고 카멜케이스 명명법으로 작성해야 한다.

Avoid using underscores in the entity property names if you have control over the property naming. This will resolve your repository woes, and will result in a cleaner code-base. Developers dealing with the code after you will thank you.

[참고 사이트] (https://stackoverflow.com/questions/29983047/spring-data-jpa-repository-methods-dont-recognize-property-names-with-underscor/30535949)

riverrevir commented 2 years ago

@Column을 사용할 때는 _를 사용하여 필드를 만들어도 되지만, 스프링 부트의 엔티티 변수 선언에서는 언더바를 사용하지 말아야 한다.