Google App中的应用程序身份问题
我想使用 @Embeddable 注释。因此,建议定义为应用程序身份。我创建了数据核心文档。但还是报错。
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
@Embeddable
public class Category{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
private String name;
@OneToMany(mappedBy="category",cascade=CascadeType.ALL)
private List<Product> products;
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public Category() {
}
public Category(String id,String name){
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
错误是
初始化指定元数据时遇到错误。有关详细信息,请参阅嵌套异常 严重:类实体。类别已指定 1 个主键字段,但此类使用非持久标识,应为应用程序标识。
I'd like to use @Embeddable annotation. So, it suggest to define as Application Identity. I created as the Data Nucleus Documentation. But it still error.
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
@Embeddable
public class Category{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String id;
private String name;
@OneToMany(mappedBy="category",cascade=CascadeType.ALL)
private List<Product> products;
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
public Category() {
}
public Category(String id,String name){
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Error is
Errors were encountered when initialising the specified MetaData. See the nested exceptions for details
SEVERE: Class entity.Category has been specified with 1 primary key fields, but this class is using nondurable identity and should be application identity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除@Id(以及@Entity),因为该类正在嵌入。
Remove @Id (and @Entity too for that matter) since the class is being embedded.