你的id字段没有定义默认值,而你插入的时候也没给值,当然不行把你的表删掉,重新创建
create table employee(id int  auto_incremnet  primary key, name varchar(20), password varchar(20))

解决方案 »

  1.   

    因為你的id的問題。
    把id設為自動增加。或讓id可以輸入NULL
      

  2.   

    一般是你给的id字段类型,无法自增。你是不是用的varchar做的主键
      

  3.   

    在hibernate annotation中
    使用"increment":
    @id
    @GeneratedValue(generator = "system-uuid")   
    @GenericGenerator(name = "system-uuid", strategy = "increment")
    时, 不管数据库Table主健产生SQL是否有"auto_incremnet"都可以自动产生新id但如果使用"identity":
    @id
    @GeneratedValue(generator = "system-uuid")   
    @GenericGenerator(name = "system-uuid", strategy = "identity")
    时, 数据库产生SQL要加入"auto_incremnet"才行
    create table employee(id int auto_incremnet primary key, ....这是为什么呢, 呵呵
      

  4.   

    有时候也需要注意,需要在<key></key>中,使用not-null="true"
      

  5.   

    不用注解  用XML写映射文件 XXX.hbm.xml
    主键
    <id name="id">
      <generator class="native"/>
    </id>
    为什么还会出现  Field   'id '   doesn 't   have   a   default   value    ???
    求解
      

  6.   

    就是你们用了<generator class="native"/>才会报错,不要用native,换个
      

  7.   

    我知道你的问题怎么解决,你在建表时候加上auto_incremnet这句,然后他就能自增了。