0

我一直在阅读此搜索中的许多主题,所以我真的诚实地尝试了 3 天。此时,我有了一个TaskListTopComponent(Window),以及一个名为Todo.java 的实体类。在 Todo 实体类中,我有一个列 TDDETAILS,它是 DBF 中的一个备注字段。我正在尝试使用以下代码从中获取数据:

@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>

对于如何解决此问题,我们将不胜感激。谢谢你!

编辑:

好吧,我尝试创建一个由两个文件组成的新项目 - 实体(我将其制作成一个 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 + " ]";
    }
}

检索备忘录.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);
    }
}
4

1 回答 1

1

我没有足够的知识来具体提供帮助,除了声明当类型为“备忘录”时驱动程序无法处理调用 getObject,从而导致您看到的异常。您在其他地方发布过 create-tables 不起作用 - 这可能是因为通用 DatabasePlatform 上使用的类型与 foxPro 类型不匹配 - 您可能需要为 FoxPro 创建一个 DatabasePlatform 子类以使用“逻辑”处理类型为布尔值等,如果驱动程序上有一个允许检索值的不同方法,则覆盖 getObjectFromResultSet 方法以读取“备忘录”类型。或者在下面使用驱动程序可以使用的不同类型。

于 2012-07-16T17:36:20.040 回答