JPA中id前面有空格导致的"Column 'id' not found"问题
Posted jpfss
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JPA中id前面有空格导致的"Column 'id' not found"问题相关的知识,希望对你有一定的参考价值。
问题背景
昨晚有个同事发生了一个神奇的问题,一如既往的问题,一如既然的用我写的BEJSON-JAVA代码生成器生成,却发现一直提示Column ‘id’ not found。这就很TM神奇了
2018-12-29 11:06:19.574 WARN 332172 --- [nio-7778-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S0022
2018-12-29 11:06:19.574 ERROR 332172 --- [nio-7778-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Column ‘id‘ not found.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select * from gene_sample_inventory where sample_num = ?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:242)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
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:185)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:6
解决方案
网上说mysql-connect-java
版本太低,于是从5.1升到了8.0都没用。
代码
看起来简直是完全没问题的。。。
再后来。。。看多了一眼,,,id
前面有空格,,,所以这个主键其实是 空格id
,我的天,这样mysql竟然可以通过。于是乎,问题解决了。
试验了一下,还真的是可以打空格。
以上是关于JPA中id前面有空格导致的"Column 'id' not found"问题的主要内容,如果未能解决你的问题,请参考以下文章