작성
·
237
0
spring jpa사용하지 않고 em.createquery를 사용해서 test를 실행 시켜도 무조건 에러가 뜹니다.
어디서 문제가 발생하는 걸까요?
public interface OrderRepository extends JpaRepository<Order,Long> {
List<Order> findByMarketAndTransactionPrice(String market,Double transactionPrice);
@Query("select o from Order o")
List<Order> findPlz();
List<Order> findByMarketAndTransactionPriceAndTradeStatusAndStatus(String market, Double transactionPrice, OrderTradeStatus tradeStatus, OrderStatus status);
}
@Test
public void errorTest() throws Exception {
//given
orderRepository.findPlz();
//when
//then
}
; 2021-06-15 03:03:55.491 INFO 17208 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test: [DefaultTestContext@31edaa7d testClass = OrderRepositoryTest, testInstance = com.gon.coin.demotradingcoin.repository.OrderRepositoryTest@19c578bf, testMethod = errorTest@OrderRepositoryTest, testException = org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select order0_.order_id as order_id1_5_, order0_.created_date as created_2_5_, order0_.excution_time as excution3_5_, order0_.market as market4_5_, order0_.member_id as member_i9_5_, order0_.status as status5_5_, order0_.trade_status as trade_st6_5_, order0_.trading_volume as trading_7_5_, order0_.transaction_price as transact8_5_ from order order0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement, mergedContextConfiguration = [WebMergedContextConfiguration@26adfd2d testClass = OrderRepositoryTest, locations = '{}', classes = '{class com.gon.coin.demotradingcoin.DemoTradingCoinApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@5656be13, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@71d44a3, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@34123d65, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4afcd809], 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.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select order0_.order_id as order_id1_5_, order0_.created_date as created_2_5_, order0_.excution_time as excution3_5_, order0_.market as market4_5_, order0_.member_id as member_i9_5_, order0_.status as status5_5_, order0_.trade_status as trade_st6_5_, order0_.trading_volume as trading_7_5_, order0_.transaction_price as transact8_5_ from order order0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527) at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:144) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$ExposeRepositoryInvocationInterceptor.invoke(CrudMethodMetadataPostProcessor.java:364) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy133.findPlz(Unknown Source) at com.gon.coin.demotradingcoin.repository.OrderRepositoryTest.errorTest(OrderRepositoryTest.java:103) 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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) 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:182) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1984) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1914) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892) at org.hibernate.loader.Loader.doQuery(Loader.java:937) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340) at org.hibernate.loader.Loader.doList(Loader.java:2689) at org.hibernate.loader.Loader.doList(Loader.java:2672) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506) at org.hibernate.loader.Loader.list(Loader.java:2501) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508) at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505) at org.hibernate.query.Query.getResultList(Query.java:132) at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:129) at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136) at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ... 42 more Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT ORDER0_.ORDER_ID AS ORDER_ID1_5_, ORDER0_.CREATED_DATE AS CREATED_2_5_, ORDER0_.EXCUTION_TIME AS EXCUTION3_5_, ORDER0_.MARKET AS MARKET4_5_, ORDER0_.MEMBER_ID AS MEMBER_I9_5_, ORDER0_.STATUS AS STATUS5_5_, ORDER0_.TRADE_STATUS AS TRADE_ST6_5_, ORDER0_.TRADING_VOLUME AS TRADING_7_5_, ORDER0_.TRANSACTION_PRICE AS TRANSACT8_5_ FROM ORDER[*] ORDER0_ "; expected "identifier"; SQL statement: select order0_.order_id as order_id1_5_, order0_.created_date as created_2_5_, order0_.excution_time as excution3_5_, order0_.market as market4_5_, order0_.member_id as member_i9_5_, order0_.status as status5_5_, order0_.trade_status as trade_st6_5_, order0_.trading_volume as trading_7_5_, order0_.transaction_price as transact8_5_ from order order0_ [42001-199] at org.h2.message.DbException.getJdbcSQLException(DbException.java:451) at org.h2.message.DbException.getJdbcSQLException(DbException.java:427) at org.h2.message.DbException.getSyntaxError(DbException.java:243) at org.h2.command.Parser.readColumnIdentifier(Parser.java:4530) at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:4491) at org.h2.command.Parser.readTableFilter(Parser.java:1853) at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:2641) at org.h2.command.Parser.parseSelectSimple(Parser.java:2788) at org.h2.command.Parser.parseSelectSub(Parser.java:2636) at org.h2.command.Parser.parseSelectUnion(Parser.java:2469) at org.h2.command.Parser.parseSelect(Parser.java:2440) at org.h2.command.Parser.parsePrepared(Parser.java:814) at org.h2.command.Parser.parse(Parser.java:788) at org.h2.command.Parser.parse(Parser.java:760) at org.h2.command.Parser.prepareCommand(Parser.java:683) at org.h2.engine.Session.prepareLocal(Session.java:627) at org.h2.server.TcpServerThread.process(TcpServerThread.java:270) at org.h2.server.TcpServerThread.run(TcpServerThread.java:175) at java.base/java.lang.Thread.run(Thread.java:831) at org.h2.message.DbException.getJdbcSQLException(DbException.java:451) at org.h2.engine.SessionRemote.done(SessionRemote.java:607) 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:477) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292) at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:77) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:349) at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:311) at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java) at com.p6spy.engine.wrapper.ConnectionWrapper.prepareStatement(ConnectionWrapper.java:118) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172) ... 73 more
답변 2
1
감사합니당. Jpql문법을잘못쓴줄알았는데메서드이름때문이었군요....
++++++ Order 테이블명을 그대로 냅둬서 db에서 오류가 난거였네요 실수로 테이블명 바꾸는 어노테이션을 지워서 한참 헤멨네요
1
안녕하세요.
첨부하신 콘솔 결과 보면 나와있듯이
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "SELECT ORDER0_.ORDER_ID A
잘못된 문법 오류로, 작성하신 JPQL은 Order를 전부 조회하는 쿼리인데요,
작성하신 findPlz 대신 findAll로 수정하시면 될 것 같네요 ^^
감사합니다
안녕하세요 이효곤님!
.
OMG님이 말씀하신것처럼 findAll()로 수정하시면 정상 처리 되실것 같습니다.
Spring Data JPA에서 findXxx 라는 메서드 이름은 특별한 의미를 갖고 있기때문에
사용자가 임의의 메서드를 만들고 싶을떈 findXxx 이름을 피하시는게 좋습니다.
.
감사합니다.