jpa执行sql语句,报错Culumn 'type_str' not found
Hibernate: select * from messagerecord m where m.touserphone=? order by m.sendtime desc
2019-08-08 14:24:41.635 WARN 53468 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S0022
2019-08-08 14:24:41.636 ERROR 53468 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : Column 'type_str' not found.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select * from messagerecord m where m.touserphone=? order by m.sendtime desc]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
但是我实体类和数据库的字段都没有字段 ‘type_str’
数据库如下:
实体类:
经过排查,纠结以及实验,终于发现错在什么地方,实体类的字段‘typeStr’是大写的,改成小写就可以了。
总结:因为对jpa文档不是很熟悉,不知道是不是jpa查询数据转化成实体的时候会把实体类中大写的字段用 '_'分离,希望以后注意。
如有更多jpa读取mysql字段大小写的问题,请多指教