我有一个使用sqlite最新版本(3.40.1.0)和openjpa-all最新版本(3.2.2)的Web应用程序项目。
我使用sqlite3命令和以下查询创建了一个虚拟数据库:
CREATE TABLE test (
id INTEGER PRIMARY KEY NOT NULL,
user TEXT COLLATE NOCASE NOT NULL
);
INSERT INTO test VALUES (1,'test');
使用openjpa-all来恢复数据(select语句),从openjpa框架得到一个错误消息,说USER0列无效。相反,我使用了正确的列名'user',并且由于某种原因框架将列名切换为USER0。
有解决的线索吗?
以下是例外情况:
Exception in thread "main" <openjpa-3.2.2-re5933d6 fatal general error> org.apache.openjpa.persistence.PersistenceException: [SQLITE_ERROR] SQL error or missing database (no such column: t0.USER0) {SELECT t0.id, t0.USER0 FROM test t0} [code=1, state=null]
FailedObject: SELECT a FROM Test a [java.lang.String]
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:5326)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:5286)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:134)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:115)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:67)
at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.handleCheckedException(SelectResultObjectProvider.java:162)
at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:42)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1314)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1061)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:911)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:842)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:601)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:297)
at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:314)
at com.kyndryl.main.Testando.main(Testando.java:31)
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: [SQLITE_ERROR] SQL error or missing database (no such column: t0.USER0) {SELECT t0.id, t0.USER0 FROM test t0} [code=1, state=null]
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:199)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$000(LoggingConnectionDecorator.java:58)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:252)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:138)
at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:144)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:138)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection.prepareStatement(JDBCStoreManager.java:1699)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:127)
at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:517)
at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:497)
at org.apache.openjpa.jdbc.sql.SelectImpl.prepareStatement(SelectImpl.java:511)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:452)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:423)
at org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect.execute(LogicalUnion.java:477)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:259)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:248)
at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:95)
at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
... 8 more
NestedThrowables:
org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: t0.USER0)
at org.sqlite.core.DB.newSQLException(DB.java:1179)
at org.sqlite.core.DB.newSQLException(DB.java:1190)
at org.sqlite.core.DB.throwex(DB.java:1150)
at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
at org.sqlite.core.NativeDB.prepare(NativeDB.java:126)
at org.sqlite.core.DB.prepare(DB.java:264)
at org.sqlite.core.CorePreparedStatement.<init>(CorePreparedStatement.java:46)
at org.sqlite.jdbc3.JDBC3PreparedStatement.<init>(JDBC3PreparedStatement.java:31)
at org.sqlite.jdbc4.JDBC4PreparedStatement.<init>(JDBC4PreparedStatement.java:25)
at org.sqlite.jdbc4.JDBC4Connection.prepareStatement(JDBC4Connection.java:34)
at org.sqlite.jdbc3.JDBC3Connection.prepareStatement(JDBC3Connection.java:226)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:140)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:249)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:138)
at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:144)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:138)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection.prepareStatement(JDBCStoreManager.java:1699)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:127)
at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:517)
at org.apache.openjpa.jdbc.sql.SQLBuffer.prepareStatement(SQLBuffer.java:497)
at org.apache.openjpa.jdbc.sql.SelectImpl.prepareStatement(SelectImpl.java:511)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:452)
at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:423)
at org.apache.openjpa.jdbc.sql.LogicalUnion$UnionSelect.execute(LogicalUnion.java:477)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:259)
at org.apache.openjpa.jdbc.sql.LogicalUnion.execute(LogicalUnion.java:248)
at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:95)
at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1314)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1061)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:911)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:842)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:601)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:297)
at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:314)
at com.kyndryl.main.Testando.main(Testando.java:31)
这是下面的代码,我没有恢复数据:
package com.company.entities;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "test")
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Basic(optional = false)
@Column(name = "user", nullable = false)
private String name;
public Test() {
super();
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Teste [id=" + id + ", name=" + name + "]";
}
}
1条答案
按热度按时间o0lyfsai1#
我找到了解决方法。比我想象的要简单得多。在列名中添加双引号。请参见下面的name属性的列注解。