2012-06-07 18 views
0

從遠程客戶端查詢select到apache cayenne服務器時,出現以下問題。Apache Cayenne中的NoSuchFieldException使用反向Engeneered對象時

爲了測試目的,我從一個表中只生成一個獨立的類。我生成了cleint類(超類和子類)和Server類。我啓動了服務器,如卡宴教程中所示。日誌告訴我,一切都很好。現在,我嘗試與客戶端連接如所示辣椒教程:

ClientConnection connection = new HessianConnection(
      "http://localhost:8080/hdlist_cayeene_javafx/cayenne-service"); 
    DataChannel channel = new ClientChannel(connection); 
    ObjectContext context = new CayenneContext(channel); 

    SelectQuery select = new SelectQuery(Source.class); 
    List<Source> sources= context.performQuery(select); 
    System.out.println(sources); 

當涉及到行:

List<Source> sources= context.performQuery(select); 

然後我得到一個異常這樣的: java.lang.NoSuchFieldException :id at org.apache.cayenne.reflect.FieldAccessor.lookupFieldInHierarchy(FieldAccessor.java:156) at org.apache.cayenne.reflect.FieldAccessor。java.lang.Class.getDeclaredField(Class.java:1899) lookupFieldInHierarchy(FieldAccessor.java:165) at org。 (org.apache.cayenne.reflect.FieldAccessor。(FieldAccessor.java:49) at org.apache.cayenne.reflect.PersistentDescriptorFactory.createAccessor(PersistentDescriptorFactory的.java:355) 在org.apache.cayenne.reflect.PersistentDescriptorFactory.createAttributeProperty(PersistentDescriptorFactory.java:147)

關於它的瘋狂的事情是,當我清空表「源」,那麼一切工作正常,我也得到一個空列表沒有任何例外。

另外它對我來說還不清楚,我可以查詢我的課程集中的所有10個對象,並且例外總是碰到所選課程的第一個屬性。如果我看看這些課程,那麼這個領域就在那裏。它們位於卡宴建模器生成的抽象類中,它們具有該例外給出的確切名稱。

這裏是客戶端上的源類:

public abstract class _Source extends PersistentObject { 

public static final String ID_PROPERTY = "id"; 
public static final String NAME_PROPERTY = "name"; 

protected Long id; 
protected String name; 

public Long getId() { 
    if(objectContext != null) { 
     objectContext.prepareForAccess(this, "id", false); 
    } 

    return id; 
} 
public void setId(Long id) { 
    if(objectContext != null) { 
     objectContext.prepareForAccess(this, "id", false); 
    } 

    Object oldValue = this.id; 
    this.id = id; 

    // notify objectContext about simple property change 
    if(objectContext != null) { 
     objectContext.propertyChanged(this, "id", oldValue, id); 
    } 
} 

public String getName() { 
    if(objectContext != null) { 
     objectContext.prepareForAccess(this, "name", false); 
    } 

    return name; 
} 
public void setName(String name) { 
    if(objectContext != null) { 
     objectContext.prepareForAccess(this, "name", false); 
    } 

    Object oldValue = this.name; 
    this.name = name; 

    // notify objectContext about simple property change 
    if(objectContext != null) { 
     objectContext.propertyChanged(this, "name", oldValue, name); 
    } 
} 

}

,這是對應的服務器類:

public abstract class _Source extends CayenneDataObject { 

public static final String ID_PROPERTY = "id"; 
public static final String NAME_PROPERTY = "name"; 

public static final String ID_PK_COLUMN = "ID"; 

public void setId(Long id) { 
    writeProperty("id", id); 
} 
public Long getId() { 
    return (Long)readProperty("id"); 
} 

public void setName(String name) { 
    writeProperty("name", name); 
} 
public String getName() { 
    return (String)readProperty("name"); 
} 

}

我用卡宴服務器和Jetty WebServer上的客戶端3.0RC3,如卡宴中所示教程。

有沒有人知道爲什麼會發生這種異常?

回答

0

下投票

所以我發現它自己: 這個錯誤最常見的原因是你忘了與客戶端實體提供的服務器作爲這裏所說的辣椒教程裏面:

https://cwiki.apache.org/CAYDOC12/remote-object-persistence-tutorial-webservice.html

"As of version 1.2, both client and server persistent classes need to be present on the server (client of course only needs client classes). This is a minor inconvenience that will be addressed in the future releases." 

所以,簡單地創建共享項目,並做客戶端和服務器項目

內行家依賴3210

祝你好運

0

客戶端查詢中使用的「源」類是否可能真的是服務器版本,而不是客戶端?

+0

因此,當我在我的回答中寫道,我沒有包括客戶端類在我的服務器的Web應用程序。這會導致問題。無論如何,它現在消失了。 – cpasemann