sql查询报java.sql.SQLException: Column 'LC_ID' not found 的错误实际上是mysql在hibernate别名的问题
2014-12-04 16:46
741 查看
报java.sql.SQLException: Column 'LC_ID' not found 的错误实际上是mysql在hibernate别名的问题
我的查询sql是 String sql2 ="select lc.lc_id lcId from Uum_Logincheck lc ";
信息: Server startupin 13441 ms
select lc.LC_ID lcId fromUum_Logincheck lc
2014-12-04 15:36:06,305 INFO[org.hibernate.type.IntegerType] 40982 - <could not read column value fromresult set: LC_ID; Column 'LC_ID' not found.>
2014-12-04 15:36:06,311 WARN[org.hibernate.util.JDBCExceptionReporter] 40988 - <SQL Error: 0, SQLState:S0022>
2014-12-04 15:36:06,311 ERROR[org.hibernate.util.JDBCExceptionReporter] 40988 - <Column 'LC_ID' notfound.>
2014-12-4 15:36:10org.apache.catalina.core.StandardWrapperValve invoke
严重:Servlet.service() for servlet spring-mvc threw exception
java.sql.SQLException: Column 'LC_ID' not found.
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
atcom.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
一开始我是用“could not read column value fromresult set: LC_ID; Column 'LC_ID' not found.”在网上找,把我的映射文件的上的
@Column(name = "LC_ID", unique = true, nullable = false)
public Integer getLcId() {
return this.lcId;
}
public void setLcId(Integer lcId) {
this.lcId = lcId;
}
吧 "LC_ID"改为lc_id 或者把sql查询中的改为大小LC_ID结构执行还是说Column 'LC_ID' not found.
还有说是要升级包mysql-connector-java-5.1.15-bin.jar,我在工程上右键,选择properties,点击java build path,选择libraries,点击add jars按钮,把那个jar包加进去,升级了还是没有用
还有说改hibernate的配置文件的。。。
后面继续百度发现有说去掉别名能成功,加上就报错的这个问题,我就改朝 hibernate别名方向搜,果真找到了答案
后面找到一段话“估计是hibernate的bug” ,“MySql数据库Hibernate不能使用别名问题解决”
最后在数据库连接的地方加了参数值=jdbc:mysql://localhost:3306/jwerp?characterEncoding=utf-8&useOldAliasMetadataBehavior=true,我这里加2个参数会报错我我就改用了 “<value>jdbc:mysql://127.0.0.1:3306/aa?useOldAliasMetadataBehavior=true</value>”,这样就ok了
希望对有遇到同样问题的人有帮助
我的查询sql是 String sql2 ="select lc.lc_id lcId from Uum_Logincheck lc ";
信息: Server startupin 13441 ms
select lc.LC_ID lcId fromUum_Logincheck lc
2014-12-04 15:36:06,305 INFO[org.hibernate.type.IntegerType] 40982 - <could not read column value fromresult set: LC_ID; Column 'LC_ID' not found.>
2014-12-04 15:36:06,311 WARN[org.hibernate.util.JDBCExceptionReporter] 40988 - <SQL Error: 0, SQLState:S0022>
2014-12-04 15:36:06,311 ERROR[org.hibernate.util.JDBCExceptionReporter] 40988 - <Column 'LC_ID' notfound.>
2014-12-4 15:36:10org.apache.catalina.core.StandardWrapperValve invoke
严重:Servlet.service() for servlet spring-mvc threw exception
java.sql.SQLException: Column 'LC_ID' not found.
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
atcom.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
一开始我是用“could not read column value fromresult set: LC_ID; Column 'LC_ID' not found.”在网上找,把我的映射文件的上的
@Column(name = "LC_ID", unique = true, nullable = false)
public Integer getLcId() {
return this.lcId;
}
public void setLcId(Integer lcId) {
this.lcId = lcId;
}
吧 "LC_ID"改为lc_id 或者把sql查询中的改为大小LC_ID结构执行还是说Column 'LC_ID' not found.
还有说是要升级包mysql-connector-java-5.1.15-bin.jar,我在工程上右键,选择properties,点击java build path,选择libraries,点击add jars按钮,把那个jar包加进去,升级了还是没有用
还有说改hibernate的配置文件的。。。
后面继续百度发现有说去掉别名能成功,加上就报错的这个问题,我就改朝 hibernate别名方向搜,果真找到了答案
后面找到一段话“估计是hibernate的bug” ,“MySql数据库Hibernate不能使用别名问题解决”
最后在数据库连接的地方加了参数值=jdbc:mysql://localhost:3306/jwerp?characterEncoding=utf-8&useOldAliasMetadataBehavior=true,我这里加2个参数会报错我我就改用了 “<value>jdbc:mysql://127.0.0.1:3306/aa?useOldAliasMetadataBehavior=true</value>”,这样就ok了
希望对有遇到同样问题的人有帮助
相关文章推荐
- sql查询报java.sql.SQLException: Column 'LC_ID' not found 的错误实际上是mysql在hibernate别名的问题
- java.sql.SQLException:Unknown column 'admin' in 'where clause'错误问题
- 关于Column '*' not found 解决方案 Hibernate使用SQL查询返回实体类型,即返回某个类,或实体类
- java.sql.SQLException: Incorrect integer value: '' for column 'id' at row 1
- hibernate 出现Caused by: java.sql.SQLException: Column 'id' not found.异常
- 关于mysql的java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F…'问题
- mysql 数据库字段为datetime类型时默认值为:0000-00-00 00:00:00 查询时异常 java.sql.SQLException:Value '0000-00-00' can not be represented as java.sq
- mysql对sql中别名引起的Column not found问题
- MySQL 关于 Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp 的错误
- java 访问数据库 java.sql.SQLException: Column not found的问题
- 错误java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- java.sql.SQLException: Incorrect string value: '\xE6\x88\x91\xE7\x9A\x84...' for column body
- java.sql.SQLException: Column count doesn't match value count at row 1
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- mysql,hibernate Column '' not found
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) at com.mysql