인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

박정훈님의 프로필 이미지
박정훈

작성한 질문수

스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술

다음으로

질문 있습니다!

작성

·

428

0

강사님 제가 스프링 입문 강의에서 만든 프로젝트에서 member클래스에 phoneNumber라는 이름으로 varchar(255)형 필드를 하나 추가했습니다. memberForm에도 추가를 해주고 스프링 통합 테스트를 돌릴 때도 member 객체를 생성하고 set으로  phoneNumber를 추가를 해줬는데도 다음과 같은 오류가 납니다. 왜 그런 걸까요 ㅠ (오류 코드는 아래와 같습니다.)

2021-03-06 21:46:04.645  INFO 14452 --- [           main] o.s.t.c.transaction.TransactionContext   : Began transaction (1) for test context [DefaultTestContext@5b068087 testClass = MemberServiceIntegrationTest, testInstance = hello.project1.service.MemberServiceIntegrationTest@1b800a11, testMethod = 회원가입@MemberServiceIntegrationTest, testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@6f152006 testClass = MemberServiceIntegrationTest, locations = '{}', classes = '{class hello.project1.Project1Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@387a8303, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@d2de489, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@41330d4f, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@24c1b2d2, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@565f390, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@7f416310], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@652a1a17]; rollback [true]

Hibernate: select member0_.id as id1_0_, member0_.name as name2_0_, member0_.phone_number as phone_nu3_0_ from member member0_ where member0_.name=?

2021-03-06 21:46:05.163  WARN 14452 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 42122, SQLState: 42S22

2021-03-06 21:46:05.163 ERROR 14452 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column "MEMBER0_.PHONE_NUMBER" not found; SQL statement:

select member0_.id as id1_0_, member0_.name as name2_0_, member0_.phone_number as phone_nu3_0_ from member member0_ where member0_.name=? [42122-200]

2021-03-06 21:46:05.189  INFO 14452 --- [           main] o.s.t.c.transaction.TransactionContext   : Rolled back transaction for test: [DefaultTestContext@5b068087 testClass = MemberServiceIntegrationTest, testInstance = hello.project1.service.MemberServiceIntegrationTest@1b800a11, testMethod = 회원가입@MemberServiceIntegrationTest, testException = javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement, mergedContextConfiguration = [WebMergedContextConfiguration@6f152006 testClass = MemberServiceIntegrationTest, locations = '{}', classes = '{class hello.project1.Project1Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@387a8303, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@d2de489, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@41330d4f, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@24c1b2d2, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@565f390, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@7f416310], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.populatedRequestContextHolder' -> true, 'org.springframework.test.context.web.ServletTestExecutionListener.resetRequestContextHolder' -> true, 'org.springframework.test.context.event.ApplicationEventsTestExecutionListener.recordApplicationEvents' -> false]]

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement

at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)

at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1602)

at org.hibernate.query.Query.getResultList(Query.java:165)

at hello.project1.repository.JpaMemberRepository.findByName(JpaMemberRepository.java:33)

at hello.project1.service.MemberService.validateDuplicateMember(MemberService.java:26)

at hello.project1.service.MemberService.join(MemberService.java:20)

at hello.project1.service.MemberService$$FastClassBySpringCGLIB$$9f40d288.invoke(<generated>)

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)

at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)

at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)

at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)

at hello.project1.service.MemberService$$EnhancerBySpringCGLIB$$b4c4763a.join(<generated>)

at hello.project1.service.MemberServiceIntegrationTest.회원가입(MemberServiceIntegrationTest.java:30)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:566)

at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)

at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)

at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)

at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)

at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)

at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)

at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)

at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)

at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)

at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)

at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement

at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)

at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)

at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)

at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:151)

at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2103)

at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2040)

at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2018)

at org.hibernate.loader.Loader.doQuery(Loader.java:948)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)

at org.hibernate.loader.Loader.doList(Loader.java:2849)

at org.hibernate.loader.Loader.doList(Loader.java:2831)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2663)

at org.hibernate.loader.Loader.list(Loader.java:2658)

at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)

at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)

at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)

at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1414)

at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1625)

at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1593)

... 82 more

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "MEMBER0_.PHONE_NUMBER" not found; SQL statement:

select member0_.id as id1_0_, member0_.name as name2_0_, member0_.phone_number as phone_nu3_0_ from member member0_ where member0_.name=? [42122-200]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)

at org.h2.message.DbException.get(DbException.java:205)

at org.h2.message.DbException.get(DbException.java:181)

at org.h2.expression.ExpressionColumn.getColumnException(ExpressionColumn.java:163)

at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:145)

at org.h2.expression.Alias.optimize(Alias.java:52)

at org.h2.command.dml.Select.prepare(Select.java:1206)

at org.h2.command.Parser.prepareCommand(Parser.java:744)

at org.h2.engine.Session.prepareLocal(Session.java:657)

at org.h2.server.TcpServerThread.process(TcpServerThread.java:278)

at org.h2.server.TcpServerThread.run(TcpServerThread.java:183)

at java.base/java.lang.Thread.run(Thread.java:834)

at org.h2.message.DbException.getJdbcSQLException(DbException.java:453)

at org.h2.engine.SessionRemote.done(SessionRemote.java:611)

at org.h2.command.CommandRemote.prepare(CommandRemote.java:85)

at org.h2.command.CommandRemote.<init>(CommandRemote.java:51)

at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:481)

at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235)

at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:76)

at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:352)

at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:337)

at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java)

at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:149)

at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:176)

... 98 more

답변 5

0

김영한님의 프로필 이미지
김영한
지식공유자

네 잘 해결하셨습니다^^

0

박정훈님의 프로필 이미지
박정훈
질문자

강사님 Member 클래스에 @Column(name = "phonenumber")을 추가해주니까 해결이 되었습니다. 감사합니다!

0

박정훈님의 프로필 이미지
박정훈
질문자

이렇게 컬럼이 추가되어있는데도 계속 같은 오류가 뜹니다..

0

박정훈님의 프로필 이미지
박정훈
질문자

감사합니다. 근데 데이터베이스에도 컬럼을 추가해줬는데도 안되는데 왜 그런걸까요?..

drop table if exists member CASCADE;

create table member

(

 id bigint generated by default as identity,

 name varchar(255),

 phoneNumber varchar(255),

 primary key (id)

);

이렇게 아예 member 테이블을 새로 생성 했는데도 안됩니다..

0

김영한님의 프로필 이미지
김영한
지식공유자

안녕하세요. 정훈님

오류 메시지를 보면 Column "MEMBER0_.PHONE_NUMBER" not found 라고 나옵니다.

JPA에 컬럼을 추가했으면 데이터베이스에도 컬럼을 추가해주셔야 합니다^^

alter table을 통해서 해당 컬럼을 추가해주세요.

감사합니다.

박정훈님의 프로필 이미지
박정훈

작성한 질문수

질문하기