Google App Engine、JDO 和 equals/hashCode

发布于 2024-08-09 10:39:19 字数 1366 浏览 5 评论 0原文

我在 Google App Engine 中有一个运行良好的应用程序。我意识到我忘记实现 equals 和 hashCode 的一个 JDO 增强对象(我需要在集合中使用该对象)。所以我做到了。我在这些实现中并没有做任何特别的事情,事实上我只是使用 Eclipse 来生成它们。就像这样:

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

现在,当我尝试访问应用程序中的任何 URL 时,都会抛出此异常:

/添加用户 javax.jdo.JDOUserException:持久类“com.bpapa.myapp.domain.User 类似乎没有得到增强。您可能需要重新运行增强器并检查输出中的错误。”数据库中没有表,但操作需要它。请检查该类的元数据规范。 在org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:427) 在 org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:249) 在 com.bpapa.myapp.servlet.AddUserServlet.doPost(AddUserServlet.java:34)

关于我做错了什么有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

挽袖吟 2024-08-16 10:39:19

Eclipse 中的配置(“运行 datanucleus 增强器”- 如上所述的相关问题)

项目设置 ->谷歌->应用程序引擎 -> ORM

将 src parh“src/”路径更改为 JDO 类的确切“src//”路径

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

甜心 2024-08-16 10:39:19

您是否将 Eclipse 设置为自动运行 datanucleus 增强器?如果您尝试使用project->clean清理项目然后从头开始构建项目会怎么样?

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?

半窗疏影 2024-08-16 10:39:19

我遇到了同样的问题,当我做这个项目时 ->干净,我在日志中看到以下异常:

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

因此,我

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

从 Eclipse 项目中删除了:,清理并重新构建,一切都开始按预期工作。

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.

暖阳 2024-08-16 10:39:19

我通过更新到最新版本的appengine java sdk解决了这个问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文