问题:
执行JPA查找时,程序报出org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet。
查看编译器给出的提示是因为查询的字段与数据库中字段不匹配。
原因:
springboot下的默认jpa会在创建拼接sql语句时自动将驼峰命名格式转为带"_"格式从而报错。
解决办法:
修改默认命名策略,替换为:PhysicalNamingStrategyStandardImpl,在application.yml配置文件下添加
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
配置好后重新运行即可·。