Question

i have the following Problem when querying a select from a remote client to apache cayenne server.

For testing purpose i generated only one independent class from one table. I generated the cleint classes (the super- and sub-class) and the Server classes. I started the server like shown in the cayenne tutorial. The log shows me that everythings fine. Now i try to connect with the client like shown in the cayenne tutorial:

    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);

When it comes to the line:

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

then i get an Exception like this: java.lang.NoSuchFieldException: id at java.lang.Class.getDeclaredField(Class.java:1899) at org.apache.cayenne.reflect.FieldAccessor.lookupFieldInHierarchy(FieldAccessor.java:156) at org.apache.cayenne.reflect.FieldAccessor.lookupFieldInHierarchy(FieldAccessor.java:165) at org.apache.cayenne.reflect.FieldAccessor.prepareField(FieldAccessor.java:103) at org.apache.cayenne.reflect.FieldAccessor.(FieldAccessor.java:49) at org.apache.cayenne.reflect.PersistentDescriptorFactory.createAccessor(PersistentDescriptorFactory.java:355) at org.apache.cayenne.reflect.PersistentDescriptorFactory.createAttributeProperty(PersistentDescriptorFactory.java:147)

the crazy thing about it is when i empty the table "Source" then everything works fine and i get an empty list back without any exception.

Also its unclear for me that i can query against all 10 objects in my class set and the exception always hit the first attribute of the selected class. If i look into these classes the field are there. They are inside the abstract classes that the cayenne modeler generates and they have the exact name that the exception gives.

here is the source class on the client:

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);
    }
}

}

and this is the corresponding server class:

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");
}

}

I use Cayenne Server and Client 3.0RC3 on a Jetty WebServer like shown in the cayenne tutorial.

Does anybody knows why this exception happens?

Was it helpful?

Solution 2

down vote

So i found it out myself: The most common reason for this error is you forgot to supply the server with the client-entities as stated here inside the cayenne tutorial:

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."

So simply create share-project and do a maven dependency inside the client- and server-project

good luck

OTHER TIPS

Is it possible that "Source" class used in the client query is really a server version, not the client?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top