Question

I’m trying to use GWT with RequestFactory and DataNucleus ( JPA with MySQL) but I can’t compile it.

The error is very strange in a proxy class : UserProxy.java:12: Could not find domain method similar to long getId()

In my domain class User.java I have such a method. I’m wondering where is the problem !!!

BTW I would appreciate if someone could show me the project with similar configuration (not with GAE) and ant build.xml file.

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

}



}
Was it helpful?

Solution 2

I would expect autoboxing to take care of the difference between "public long getId()" in the proxy and "public Long getId()" in the DTO, but perhaps you could try changing them so that they both return "long" or both return "Long".

OTHER TIPS

Long is not long. Choose one or the other, but use the same in both the domain class and the EntityProxy.

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