Google App Engine,JDO和equals / hashCode [英] Google App Engine, JDO, and equals/hashCode

查看:96
本文介绍了Google App Engine,JDO和equals / hashCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

@Persistent
私有字符串appleId;

@Override
public int hashCode(){
final int prime = 31;
int result = 1;
result = prime * result
+((appleId == null)?0:appleId.hashCode());
返回结果;

$ b @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;
返回true;
}

现在,当我尝试击中应用程序中的任何URL时,被抛出:


/ addUser
javax.jdo.JDOUserException:持续类Class com.bpapa.myapp.domain.User似乎没有得到增强,您可能需要重新运行增强器并检查输出中的错误。在数据库中没有表格,但操作需要它。请检查这个类的元数据的规范。
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)


关于我做错了什么想法?

解决方案

你有eclipse设置为自动运行datanucleus增强器吗?如果您尝试使用project-> clean清理项目并从头开始构建项目,该怎么办?

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?

解决方案

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?

这篇关于Google App Engine,JDO和equals / hashCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆