我最近刚刚对我的数据库结构进行了一些更改,当我要测试该应用程序时,它在我用于登录的简单存储库.findByEmail(email)上引发了异常。它引发了一个异常,说我创建的新表之一的列不存在(即使存在)。我在休眠状态下打开了SQL日志记录,然后复制了它显示的查询无效的查询,然后在DBeaver(我用于运行SQL命令的IDE)上运行了该查询,
Hibernate生成的SQL代码:
Hibernate:
select
profile0_.id as id1_8_0_,
profile0_.name as name2_8_0_,
roles1_.id_profile as id_profi1_9_1_,
role2_.id as id_role2_9_1_,
role2_.id as id1_10_2_,
role2_.name as name2_10_2_
from
profile profile0_
left outer join
profile_roles roles1_
on profile0_.id=roles1_.id_profile
left outer join
role role2_
on roles1_.id_role=role2_.id
where
profile0_.id=?
调试中的错误消息(我只复制了主要错误消息,但是如果有帮助,我可以发送整个调试消息:
2019-10-07 10:41:41.035 WARN 2492 --- [nio-8443-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0,
SQLState: 42703
2019-10-07 10:41:41.035 ERROR 2492 --- [nio-8443-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column profile0_.id does not exist
Posição: 245
2019-10-07 10:41:41.052 INFO 2492 --- [nio-8443-exec-6] o.h.e.internal.DefaultLoadEventListener : HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: column profile0_.id does not exist
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
答案 0 :(得分:0)
我意识到发生了什么事。我在另一个没有该列的模式上有另一个具有该名称的表。我要做的就是在@Table批注上添加schema属性