0

我正在尝试将 GWT 与 RequestFactory 和 DataNucleus(JPA 与 MySQL)一起使用,但我无法编译它。

代理类中的错误非常奇怪:UserProxy.java:12: 找不到类似于 long getId() 的域方法

在我的域类 User.java 我有这样的方法。我想知道问题出在哪里!!!

顺便说一句,如果有人可以向我展示具有类似配置(不使用 GAE)和 ant build.xml 文件的项目,我将不胜感激。

package com.test.shared;

import com.test.domain.User;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.ProxyFor;

@ProxyFor(User.class)
public interface UserProxy extends EntityProxy {

public long getId();

public void setId(Long id);

public Integer getVersion();

public String getFirstName();

public void setFirstName(String firstName);

public String getLastName();

public void setLastName(String lastName);

public String getEmail();

public void setEmail(String email);

    EntityProxyId<UserProxy> stableId();

}



package com.test.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;


@Entity
public class User {

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Version
@Column(name = "version")
private Integer version; //require to persist

@NotNull
private String firstName;

@NotNull
private String lastName;

@NotNull
private String email;

public User() {
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public Integer getVersion() {
    return version;
}

public void setVersion(Integer version) {
    this.version = version;
}

// -----------------------

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

// get EntityManager

public static final EntityManager entityManager() {
    return EMF.get().createEntityManager();
}

// implementing a service in an entity class

public static User findUserByEmail(String email) {
    if (email == null) {
        return null;
    }
    EntityManager em = entityManager(); 
    try {
        User user = em.find(User.class, email);
        return user;
    } finally {
        em.close();
    }
}

public void persist() {
    EntityManager em = entityManager();
    try {
        em.persist(this);
    } finally {
        em.close();
    }
}

public void remove() {
    EntityManager em = entityManager();
    try {
        User attached = em.find(User.class, this.id);
        em.remove(attached);
    } finally {
        em.close();
    }
}

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Id: ").append(getId()).append(", ");
    sb.append("Version: ").append(getVersion()).append(", ");
    sb.append("FirstName: ").append(getFirstName()).append(", ");
    sb.append("LastName: ").append(getLastName()).append(", ");
    sb.append("Email: ").append(getEmail()).append(";");
    return sb.toString();

}



}
4

2 回答 2

2

Long不是long。选择其中一个,但在域类和EntityProxy.

于 2013-01-04T16:26:26.540 回答
0

我希望自动装箱能够处理代理中的“public long getId()”和 DTO 中的“public Long getId()”之间的区别,但也许您可以尝试更改它们,以便它们都返回“long”或两者都返回返回“长”。

于 2013-01-04T16:26:44.607 回答