【发布时间】:2020-04-05 17:40:58
【问题描述】:
我正在使用 Spring boot 2 和 Hibernate 5
我的控制台输出
2020-04-05 19:17:20.087 WARN 3908 --- [nio-8290-exec-1] o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [328] milliseconds.
Hibernate:
insert
into
adv.t_address
(created, created_at, state, updated, updated_at, additionalNumber, apartmentNumber, city, country, number, streetName)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2020-04-05 19:17:29.347 WARN 3908 --- [nio-8290-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 42703
2020-04-05 19:17:29.347 ERROR 3908 --- [nio-8290-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column "additionalnumber" of relation "t_address" does not exist
Position: 77
2020-04-05 19:17:29.378 ERROR 3908 --- [nio-8290-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause
org.postgresql.util.PSQLException: ERROR: column "additionalnumber" of relation "t_address" does not exist
我在实体模型中的专栏
@Column(length = 50, nullable = false)
private String additionalNumber;
我也在使用这个属性
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
我的问题是:为什么我没有得到列“additionalNumber”而不是“additionalnumber”?
这是来自 DB 的日志 似乎 DB 在返回时卡住了
2020-04-05 18:41:39.856 UTC [622] STATEMENT: insert into adv.t_address (created, created_at, state, updated, updated_at, additionalNumber, apartmentNumber, city, country, number, streetName) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
rentni_db | RETURNING *
【问题讨论】:
-
你的db表列和模型变量名匹配吗?
-
是的,模型和表格列与“additionalNumber”匹配,虽然我得到了这个异常,我不知道为什么
-
可以看到插入没问题,列名正确
-
您是否尝试过一个简单的查询,它只能插入或更新附加数字,而不是尝试一个巨大的。?只是为了确保这不是您查询的问题
-
好点我去试试
标签: hibernate spring-boot jpa spring-data-jpa spring-data