【发布时间】:2021-01-11 09:49:36
【问题描述】:
为什么我在 Spring Boot Hibernate createNativeQuery 中收到此错误 Invalid column name?我正在尝试从 oracle 数据库中获取表信息。我将我的查询放入 db eaver 它的成功,请告诉我本机查询的最佳实践如何...
Hibernate: SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='BPN_AKTA'
2020-09-25 10:27:53.005 WARN 60208 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17006, SQLState: 99999
2020-09-25 10:27:53.005 ERROR 60208 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Invalid column name
2020-09-25 10:27:53.006 ERROR 60208 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query] with root cause
java.sql.SQLException: Invalid column name
Query q= em.createNativeQuery("SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='PC'",QueryTableAttModel.class);
List<QueryTableAttModel> tableColl = q.getResultList();
我的模特
@Entity(name="ALL_TAB_COLUMNS")
public class QueryTableAttModel {
public String getTABLE_NAME() {
return TABLE_NAME;
}
public void setTABLE_NAME(String TABLE_NAME) {
this.TABLE_NAME = TABLE_NAME;
}
public String getCOLUMN_NAME() {
return COLUMN_NAME;
}
public void setCOLUMN_NAME(String COLUMN_NAME) {
this.COLUMN_NAME = COLUMN_NAME;
}
public String getDATA_TYPE() {
return DATA_TYPE;
}
public void setDATA_TYPE(String DATA_TYPE) {
this.DATA_TYPE = DATA_TYPE;
}
private String TABLE_NAME;
private String COLUMN_NAME;
private String DATA_TYPE;
private String id;
@Id
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
【问题讨论】:
标签: java oracle spring-boot hibernate spring-data-jpa