spring data jpa报错 could not extract ResultSet; SQL [n/a]。数据库字段与实体类字段名不一致,需要取消自动将驼峰命名转为下划线形式

解决方法:

添加配置:spring.jpa.hibernate.naming.physical-strategy= org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

 

问题根源:

编译时报错:

org.springframework.dao.InvalidDataAccessResourceUsageException: 
could not extract ResultSet; SQL [n/a];
 nested exception is org.hibernate.exception.SQLGrammarException: 
could not extract ResultSet

无法找到数据库与实体类对应的字段导致异常。

这是因@Entity 实体类在数据库中生成表结构的时候,多个单词的字段在数据库中生成字段时加了下划线。例如:

导致我们再次在数据库做查询的时候无法找到和实体类对应的字段。

这时候需要在添加配置文件中添加配置行,取消下划线(取消自动将驼峰命名转为下划线形式)

spring.jpa.hibernate.naming.physical-strategy= org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

添加配置后:

 

详细异常信息:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

	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(ChainedPersistenceExceptionTrans
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值