我一直在閱讀this search中的很多主題,所以我真的給了它3天的誠實嘗試。此時,我有一個TaskListTopComponent(Window)和一個名爲Todo.java的實體類。在Todo實體類中,我有一個TDDETAILS列,它是DBF中的備註字段。我試圖用下面的代碼從它那裏得到的數據:嘗試訪問備忘錄字段時出錯(EclipseLink,JdbcOdbc,Clob)
@Column(name = "TDDETAILS")
@Lob
private String details;
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
如果我刪除上面的代碼,我的應用程序完美的作品和所有其他10+列可以被檢索,修改,添加和刪除。
不過,我需要的TDDETAILS場,我得到以下錯誤,當我使用上面的代碼:
Internal Exception: java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Feature is not available.
Error Code: 0
Call: SELECT TDTDKEY, TDBILLABLE, TDEMAILED, TDFLATRATE, TDADD_DATE, TDADD_TERM, TDADD_TIME, TDADD_USER, TDCHG_DATE, TDCHG_NUMB, TDCHG_TERM, TDCHG_TIME, TDCHG_USER, TDDETAILS, TDDATEDONE, TDFOLLOWUP, TDINTERNAL, TDPRIVATE, TDREQUIRED, TDSRED, TDTAKEN, TDDESCRIP, TDPRIORITY, TDCMKEY, TDCNKEY, TDJTKEY, TDPYKEY, TDURKEYAS, TDURKEYTB FROM TODO
Query: ReadAllQuery(name="Todo.findAll" referenceClass=Todo sql="SELECT TDTDKEY, TDBILLABLE, TDEMAILED, TDFLATRATE, TDADD_DATE, TDADD_TERM, TDADD_TIME, TDADD_USER, TDCHG_DATE, TDCHG_NUMB, TDCHG_TERM, TDCHG_TIME, TDCHG_USER, TDDETAILS, TDDATEDONE, TDFOLLOWUP, TDINTERNAL, TDPRIVATE, TDREQUIRED, TDSRED, TDTAKEN, TDDESCRIP, TDPRIORITY, TDCMKEY, TDCNKEY, TDJTKEY, TDPYKEY, TDURKEYAS, TDURKEYTB FROM TODO")
INFO [org.netbeans.core.windows.persistence]: [PersistenceManager.getTopComponentForID] Problem when deserializing TopComponent for tcID:'TaskListTopComponent'. Reason: Cannot create instance of com.waudware.viewer.TaskListTopComponent
我的persistence.xml看起來是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MogEntityLivedataPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>entity.Todo</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:odbc:MogDev_livedata_ODBC"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.user" value=""/>
</properties>
</persistence-unit>
</persistence>
任何幫助表示讚賞至於我如何解決這個問題。謝謝!
編輯:
好吧,我試圖創建一個新的項目,由字面上2個文件 - 實體(我使之成爲一個JAR)和一個主類:
todo.java
package entity;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "TODO")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Todo.findAll", query = "SELECT c FROM Todo c")})
public class Todo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "TDTDKEY")
private String id;
@Lob
@Column(name = "TDDETAILS")
private byte[] details;
public byte[] getDetails() {
return details;
}
public void setDetails(byte[] details) {
this.details = details;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Todo)) {
return false;
}
Todo other = (Todo) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.Todo[ id=" + id + " ]";
}
}
RetrieveMemo.java
package retrievememo;
import entity.Todo;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
public class RetrieveMemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
EntityManager entityManager = Persistence.createEntityManagerFactory("MemoEntityPU").createEntityManager();
Query query = entityManager.createNamedQuery("Todo.findAll");
List<Todo> resultList = query.getResultList();
System.out.println("Memo1:>" + resultList.get(1).getDetails() + "<");
}
}
以下是完整的堆棧跟蹤:
[EL Info]: 2012-07-16 09:10:14.382--ServerSession(20248218)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Info]: 2012-07-16 09:10:14.491--Not able to detect platform for vendor name [Visual FoxPro]. Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property eclipselink.platform.class.name.
[EL Info]: 2012-07-16 09:10:15.851--ServerSession(20248218)--file:/Y:/NetBeansProjects/MemoEntity/build/classes/_MemoEntityPU login successful
[EL Warning]: 2012-07-16 09:10:16.899--UnitOfWork(6597453)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Feature is not available.
Error Code: 0
Call: SELECT TDTDKEY, TDDETAILS FROM TODO
Query: ReadAllQuery(name="Todo.findAll" referenceClass=Todo sql="SELECT TDTDKEY, TDDETAILS FROM TODO")
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Feature is not available.
Error Code: 0
Call: SELECT TDTDKEY, TDDETAILS FROM TODO
Query: ReadAllQuery(name="Todo.findAll" referenceClass=Todo sql="SELECT TDTDKEY, TDDETAILS FROM TODO")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.getObject(DatabaseAccessor.java:1237)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.fetchRow(DatabaseAccessor.java:999)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processResultSet(DatabaseAccessor.java:723)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:566)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2592)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2551)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:418)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1097)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1056)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:390)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1144)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1457)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at retrievememo.RetrieveMemo.main(RetrieveMemo.java:26)
Caused by: java.sql.SQLException: [Microsoft][ODBC Visual FoxPro Driver]Feature is not available.
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:318)
at sun.jdbc.odbc.JdbcOdbcResultSet.getObject(JdbcOdbcResultSet.java:1678)
at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.getObjectFromResultSet(DatabasePlatform.java:1216)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.getObject(DatabaseAccessor.java:1206)
... 25 more
Java Result: 1
BUILD SUCCESSFUL (total time: 11 seconds)
EDIT2:看來工作完美無瑕,如果我確實不使用的實體。我想我的問題是 - 我怎樣才能使它與一個實體工作?問題必須與EclipseLink?
下面的方法的工作原理:
package retrievememo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class RetrieveMemo {
public static void main(String[] args) {
try {
// EntityManager entityManager = Persistence.createEntityManagerFactory("MemoEntityPU").createEntityManager();
// Query query = entityManager.createNamedQuery("Todo.findAll");
// List<Todo> resultList = query.getResultList();
// System.out.println("Memo1:>" + resultList.get(1).getDetails() + "<");
Connection conn = getConnection();
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT TDDETAILS FROM todo");
while (rs.next())
{
System.out.println(rs.getString("TDDETAILS"));
}
st.close();
conn.close();
} catch (Exception ex) {
Logger.getLogger(RetrieveMemo.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static Connection getConnection() throws Exception {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:MogDev_livedata_ODBC";
String username = "";
String password = "";
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
}
你可以發佈完整的堆棧跟蹤,並且你能夠使用JDBC直接執行相同的查詢嗎? – Chris 2012-07-13 17:27:25
@Chris我用我的最新嘗試和完整的堆棧跟蹤對我的帖子進行了編輯。 – 2012-07-16 13:18:09
@Chris我添加了一個「edit2」,它顯示了我的另一種方法(這正是我認爲你直接用JDBC的意思),它的工作原理完美無瑕。備註欄TDDETAILS顯示在輸出中。問題在於我需要使用實體。有沒有辦法讓它工作? – 2012-07-16 14:32:07