繁体   English   中英

基本”属性类型不应为“持久性实体”

[英]Basic' attribute type should not be 'Persistence Entity'

我正在使用 Spring 引导来创建我的 REST API。 我有一个“组件”class,如下:

@Entity
public class Component {
   @Id @GeneratedValue
   private Long id;
   private String name;
   private String unit;
   private double quantity;

   public Component(){

   }


   public Component(Long id, String name, String unit, double quantity){
       this.id = id;
       this.name = name;
       this.unit = unit;
       this.quantity = quantity;
   }

  //getters
  //setters

我有一个产品 class 由“组件”组成:

@Entity
public class Product{
    @Id @GeneratedValue
    private Long id;
    private String name;
    private Component productComponent;

}

这是我得到的错误:它突出显示产品 class 中的“私有组件 productComponent”行,并说明以下内容:

基本”属性类型不应为“持久性实体”

这种错误背后的原因是什么?

我通过添加@ManyToOne 和@JoinColumn 解决了上述问题:

@Entity
public class Product{
    @Id @GeneratedValue
    private Long id;
    private String name;
    @ManyToOne
    @JoinColumn
    private Component productComponent;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM