本文介绍了使列索引超出范围,0< 1个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenJPA 2.2.0,当我执行一条select语句时,出现列索引超出范围,0

I am using OpenJPA 2.2.0 and when I am executing a select statement I am getting "Column index out of range, 0 < 1" error.

EntityManager entityMgrObj = emf.getEntityManager();

entityMgrObj.clear();

Query query = entityMgrObj.createNativeQuery("select * from company_user where user_id = 1001);

List<CompanyUserDO> companyUserDOObj = null;

try {
    companyUserDOObj = query.getResultList();
} catch (Exception e) {
    System.out.println(e.getMessage());
}

当query.getResultList()执行时,出现列索引超出范围,0 <1"错误.有人可以让我知道上面的代码有什么问题吗?

When the query.getResultList() executes I get "Column index out of range, 0 < 1" error. Can somebody let me know what is wrong in the above code?

@UPDATE

当我没有捕获到异常时,控制台上会打印以下堆栈.

When I do not catch the exception following stack is printed on the console.

Exception in thread "main" <openjpa-2.2.0-r422266:1244990 fatal general error> org.apache.openjpa.persistence.PersistenceException: Column Index out of range, 0 < 1.
FailedObject: select * from company_user where user_id=1001 [java.lang.String]
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4918)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4878)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:118)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:70)
at org.apache.openjpa.jdbc.kernel.GenericResultObjectProvider.handleCheckedException(GenericResultObjectProvider.java:125)
at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:40)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1251)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
at zumigo.geofence.test.dalTest.main(dalTest.java:62)
Caused by: java.sql.SQLException: Column Index out of range, 0 < 1.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.checkColumnBounds(ResultSetImpl.java:812)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5651)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5570)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:213)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:213)
at org.apache.openjpa.lib.jdbc.DelegatingResultSet.getString(DelegatingResultSet.java:121)
at org.apache.openjpa.jdbc.sql.DBDictionary.getString(DBDictionary.java:886)
at org.apache.openjpa.jdbc.sql.ResultSetResult.getStringInternal(ResultSetResult.java:474)
at org.apache.openjpa.jdbc.sql.AbstractResult.getString(AbstractResult.java:767)
at org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy.getPrimaryKeyValue(StringFieldStrategy.java:217)
at org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java:188)
at org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java:147)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1002)
at org.apache.openjpa.jdbc.kernel.GenericResultObjectProvider.getResultObject(GenericResultObjectProvider.java:93)
at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
... 8 more

@UPDATE 2 搜索和调试后,发现persistence.xml文件指向旧数据库,因此出现上述错误.

@UPDATE 2After searching and debugging it was found that the persistence.xml file was pointing to an old database hence it was giving the above mentioned error.

更改了数据库URL,应用程序运行正常. :)

Changed the database URL and the application is working fine. :)

推荐答案

似乎jdbc中的列索引是从1计算得出的.它与数组是不同的,后者是从0计算得出的.

It seems like that column index in jdbc is computed from 1. And it's different from array, which is computed from 0.

这篇关于使列索引超出范围,0&lt; 1个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 13:34