使用 Objectify 4,当我保存 MenuItem 对象时,名称和价格字段不会保留。只有 Key、WriteOps 和 ID/Name 保留在调试数据存储区中。
@Entity
public class MenuItem extends BaseEntity {
private String name;
private double price;
public MenuItem() {
}
public MenuItem(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
BaseEntity 在哪里:
public abstract class BaseEntity implements Dto {
private static final long serialVersionUID = 8400346403708831769L;
@Id
protected Long id;
protected BaseEntity() {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.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;
}
BaseEntity other = (BaseEntity) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
return true;
}
public Long getId() {
return id;
}
public void setId(@Nullable Long id) {
this.id = id;
}
public boolean isSaved() {
return (id != null);
}
}
Dto 是:
public interface Dto extends Serializable {
}
有任何想法吗?谢谢!