Google App Engine, JDO, and equals/hashCode
Asked Answered
E

4

10

I've got an app in Google App Engine that was working fine. I realized that one on of my JDO-enhanced objects that I forgot to implement equals and hashCode (I need to use the object in a set). So I did. I didn't really do anything special in these implementations, in fact I just used Eclipse to generate them. Like so:

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

@Persistent
private String appleId;

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result
            + ((appleId == null) ? 0 : appleId.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    User other = (User) obj;
    if (appleId == null) {
        if (other.appleId != null)
            return false;
    } else if (!appleId.equals(other.appleId))
        return false;
    return true;
}

So now, when I try to hit any URLs in the app, this exception gets thrown:

/addUser javax.jdo.JDOUserException: Persistent class "Class com.bpapa.myapp.domain.User does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class. at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:427) at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:249) at com.bpapa.myapp.servlet.AddUserServlet.doPost(AddUserServlet.java:34)

Any ideas on what I did wrong?

Expendable answered 29/10, 2009 at 5:1 Comment(0)
P
11

Do you have eclipse set to automatically run the datanucleus enhancer? What if you try cleaning the project with project->clean and then build the project from scratch?

Prologue answered 29/10, 2009 at 6:7 Comment(1)
Doing the clean fixed things.Expendable
E
14

Configuration in eclipse ("run the datanucleus enhancer" - related issue as discussed above)

Project Settings -> Google -> App Engine -> ORM

Change src parh "src/" path to the exact "src//" path of your JDO classes

Erena answered 13/12, 2009 at 3:25 Comment(0)
P
11

Do you have eclipse set to automatically run the datanucleus enhancer? What if you try cleaning the project with project->clean and then build the project from scratch?

Prologue answered 29/10, 2009 at 6:7 Comment(1)
Doing the clean fixed things.Expendable
B
3

I faced the same problem, and when I did the Project -> Clean, I saw following exception in the log:

{Caused by: org.datanucleus.exceptions.NucleusException: Plugin (Bundle) "org.datanucleus.store.appengine" is already registered. Ensure you dont have multiple JAR versions of the same plugin in the classpath. The URL "file:/C:/Documents%20and%20Settings/Administrator/workspace/Guestbook/war/WEB-INF/lib/datanucleus-appengine-1.0.8.final.jar" is already registered, and you are trying to register an identical plugin located at URL "file:/C:/eclipse/plugins/com.google.appengine.eclipse.sdkbundle.1.4.2_1.4.2.v201102111811/appengine-java-sdk-1.4.2/lib/user/orm/datanucleus-appengine-1.0.8.final.jar."}

So, I removed:

C:/Documents and Settings/Administrator/workspace/Guestbook/war/WEB-INF/lib/datanucleus-appengine-1.0.8.final.jar

from the eclipse project, cleaned and re-built, everything started working as expected.

Bobbee answered 5/4, 2011 at 3:12 Comment(1)
I what log did you see that?Casserole
D
0

I solved this problem by updating to the latest version of appengine java sdk.

Doehne answered 12/8, 2013 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.