Google App中的应用程序身份问题

发布于 2024-12-05 06:21:27 字数 1330 浏览 0 评论 0原文

我想使用 @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-12-12 06:21:27

删除@Id(以及@Entity),因为该类正在嵌入。

Remove @Id (and @Entity too for that matter) since the class is being embedded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文