Spring (冬眠)可以';t添加具有多对多关系的实体

Spring (冬眠)可以';t添加具有多对多关系的实体,spring,hibernate,jpa,spring-boot,entity,Spring,Hibernate,Jpa,Spring Boot,Entity,基本上,我的目标是让产品和工厂实体之间的关系是多对多的。 工厂必须有一些产品,而产品不必与工厂关联。问题是,当我尝试添加产品实体时,会出现此错误 Caused by: org.hsqldb.HsqlException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10103 table: PRODUCT column: FACT_ID 这是我的申请课我希望能够将产品保存到存储库,而不给它工厂列表,但我遇到了

基本上,我的目标是让产品和工厂实体之间的关系是多对多的。 工厂必须有一些产品,而产品不必与工厂关联。问题是,当我尝试添加产品实体时,会出现此错误

Caused by: org.hsqldb.HsqlException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10103 table: PRODUCT column: FACT_ID
这是我的申请课我希望能够将产品保存到存储库,而不给它工厂列表,但我遇到了错误,因此我尝试添加注释中的内容,但仍然存在相同的错误

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    private ProductRepo prodRepo;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    @Transactional
    public void run(String... strings) throws Exception {
    Product one = new Product();
  /*
    List<Product> productList= new ArrayList<Product>();
    productList.add(one);

    SomeFactory factory_one = new SomeaFactory("one", productList);
    List<Factory> factoryList = new ArrayList<Factory>();
    factoryList.add(factory_one);

    one.setFactoryList(factoryList);
  */
    prodRepo.save(one);
}

联接表与另一个实体具有相同的名称是有意的吗?在联接中,您可以说
@JoinColumn(name=“FACT\u ID”,nullable=true)
,但是列
FACT\u ID
持有主键(请参见
工厂
类),因此它永远不能是
null
。当我更改表的名称时,它起作用了!谢谢!!
@Entity
@Table(name="PRODUCT")
public class Product {
    private int id;
    private List<Factory> factoryList = null;

    public Product() {}

    @Id
    @Column(name = "PROD_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId()                  { return id; }
    public void setId(int id)           { this.id = id; }

    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "productList", targetEntity = Factory.class)
    public List<Factory> getFactoryList() {
        return factoryList;
    }
    public void setFactoryList(List<Factory> f) {
        this.factoryList = f;
    }

}
@Entity
@Table(name ="SOME_FACT")
public class SomeFactory extends Factory {
    private String name;
    private List<Product> productList;

    public SomeFactory() {}
    public SomeFactory(String name, List<Product> products) {
        this.name = name;
        this.productList = products;
    }

    @Column(name = "FACT_NAME", nullable = false)
    public String getName()             { return name; }
    public void setName(String name)    { this.name = name; }

    @ManyToMany
    @JoinTable(name = "PRODUCT",
            joinColumns = @JoinColumn(name = "FACT_ID", nullable = true),
            inverseJoinColumns = @JoinColumn(name = "PROD_ID", nullable = false))
    public List<Product> getProductList() {
        return productList;
    }
    public void setProductList(List<Product> products) {
        this.productList = products;
    }
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Factory {
    int id;

    public Factory() {}

    @Id
    @Column(name="FACT_ID")
    @GeneratedValue(strategy = GenerationType.TABLE)
    int getId()                     { return id; }
    void setId(int id)              { this.id = id; }
}