码迷,mamicode.com
首页 > 其他好文 > 详细

JPA中id前面有空格导致的"Column 'id' not found"问题

时间:2019-07-10 18:40:44      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:proc   har   cte   follow   hiberna   sar   RKE   通过   not   

问题背景

昨晚有个同事发生了一个神奇的问题,一如既往的问题,一如既然的用我写的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竟然可以通过。于是乎,问题解决了。

技术图片

试验了一下,还真的是可以打空格。
技术图片

原文地址:https://blog.csdn.net/moshowgame/article/details/85336333

JPA中id前面有空格导致的"Column 'id' not found"问题

标签:proc   har   cte   follow   hiberna   sar   RKE   通过   not   

原文地址:https://www.cnblogs.com/jpfss/p/11165518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!