请教一个问题
nested exception is java.sql.BatchUpdateException: Field 'categoryId' doesn't have a default value categoryId是我表的外键我update可以正常update.但save就抛出上面的异常.是我的mysql问题还是我配置有问题?谢谢高手们 public void setCategory(Category category){
this.category = category;
}

@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "categoryId",nullable = false, insertable = false, updatable = false)
public Category getCategory() {
return category;
}         public void setCategoryId(java.lang.Long value) {
this.categoryId = value;
}

@Id @GeneratedValue(generator="custom-id")
@GenericGenerator(name="custom-id", strategy = "increment")
@Column(name = "categoryId", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
public java.lang.Long getCategoryId() {
return this.categoryId;
}

解决方案 »

  1.   

    你save的那个对象的category属性为null
      

  2.   

    如果是null我update也不会成功啊.我update成功
      

  3.   

    this.category 和this.categoryId 什么关系?
      

  4.   

    //columns START
    private java.lang.Long categoryId;
    private java.lang.String categoryName;
    private java.lang.String re;
    //columns END
    public Category(){
    } public Category(
    java.lang.Long categoryId
    ){
    this.categoryId = categoryId;
    } public void setCategoryId(java.lang.Long value) {
    this.categoryId = value;
    }

    @Id @GeneratedValue(generator="custom-id")
    @GenericGenerator(name="custom-id", strategy = "increment")
    @Column(name = "categoryId", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
    public java.lang.Long getCategoryId() {
    return this.categoryId;
    }
      

  5.   

    我有一个goods表和category表 category是goods表的外键.categoryId是category表的主键.goods 是many to one category的关系 外键是categoryId
      

  6.   

    categoryId是主键吧,你怎么说是外键这个:
    @Id @GeneratedValue(generator="custom-id") 
    @GenericGenerator(name="custom-id", strategy = "increment")是什么意思,MYSQL支持么?问题应该在这里,主键没有自动生成
      

  7.   

    @GenericGenerator(name="custom-id", strategy = "increment") 
    策略不设置或者是设置为identity