다른 db에 적용했을 때에는 잘 돌아가는데 가끔 이런 오류가 뜰 때가 있습니다.
저는 프론트는 react, 백은 spring, DB는 mysql을 사용하고 있습니다.
프론트 문제인지 백 문제인지 알아보기 위해서 Postman을 다운받아 백에 post를 보내면 잘 적용되는지 확인해 보았습니다.
https://www.postman.com/downloads/
Postman의 활용방법은 아래 블로그를 참고하였습니다.
https://meetup.toast.com/posts/107
그 결과 다음과 같은 오류를 받을 수 있었습니다.
{
"timestamp": "2021-02-11T08:30:25.963+00:00",
"status": 500,
"error": "Internal Server Error",
"trace": "org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement\r\n\tat org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:353)\r\n\tat org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)\r\n\tat org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)\r\n\tat org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)\r\n\tat org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)\r\n\tat org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:154)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)\r\n\tat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\r\n\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)\r\n\tat com.sun.proxy.$Proxy105.save(Unknown Source)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:564)\r\n\tat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)\r\n\tat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)\r\n\tat com.sun.proxy.$Proxy74.save(Unknown Source)\r\n\tat com.board.back.service.UserService.createUser(UserService.java:22)\r\n\tat com.board.back.controller.UserController.createUser(UserController.java:30)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:564)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)\r\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)\r\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)\r\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:652)\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:733)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\r\n\tat org.springframework.web.filter.RequestContextFilter.doFilterIntern
이래저래 해보던 끝에 값이 null로 받아지는 것이 문제인것 같아서 여러가지 시도를 하다가 제가 찾은 해결책은 아래와 같습니다. spring 코드들 중 model에서부터 값이 null로 받아지는 것 같아 model의 코드를 수정하였습니다.
User.java
package com.board.back.model;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
//유저테이블
@Entity
@Table(name = "user")
@DynamicInsert
@DynamicUpdate
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_no")
private Integer user_no;
// 아이디(학번)
@Column(name = "user_id")
private Integer user_id;
// 비밀번호
@Column(name = "user_pw")
private String user_pw;
// 전공
@Column(name = "user_major")
private Integer user_major;
// 학년
@Column(name = "user_grade")
private Integer user_grade;
public Integer getNo() {
return user_no;
}
public void setNo(Integer user_no) {
this.user_no = user_no;
}
public Integer getId() {
return user_id;
}
public void setId(Integer user_id) {
this.user_id = user_id;
}
public String getPassword() {
return user_pw;
}
public void setPassword(String user_pw) {
this.user_pw = user_pw;
}
public Integer getMajor() {
return user_major;
}
public void setMajor(Integer user_major) {
this.user_major = user_major;
}
public Integer getGrade() {
return user_grade;
}
public void setGrade(Integer user_grade) {
this.user_grade = user_grade;
}
/*이 코드를 삭제함
public User() {
super();
}*/
public User(Integer user_id, String user_pw, Integer user_major, Integer user_grade) {
super();
this.user_id = user_id;
this.user_pw = user_pw;
this.user_major = user_major;
this.user_grade = user_grade;
}
@Override
public String toString() {
return "User [user_no=" + user_no + ", id=" + user_id + ", password=" + user_pw + ", major=" + user_major
+ ", grade=" + user_grade + "]";
}
}
다른 db에서는 이 코드가 있어도 잘 굴러갔는데 이 model은 아래 코드를 지우면 정상적으로 작동됩니다.
public User() {
super();
}