@Lob字段在@Column中使用nullable=false导致hibernate无法自动建表

来源:互联网 发布:python 释放内存对象 编辑:程序博客网 时间:2024/06/07 04:42

定义了一个报告类,其中报告内容content使用@Lob定义为大数据字段

@Embeddablepublic class ReportPo{  @Column(name="report_title")  private String title;  @ManyToOne(targetEntity=AccountPo.class)  @JoinColumn(name="report_tester", referencedColumnName="account_id", nullable=false)  private AccountPo tester;  @ManyToOne(targetEntity=AccountPo.class)  @JoinColumn(name="report_reporter", referencedColumnName="account_id", nullable=false)  private AccountPo reporter;  @ManyToOne(targetEntity=AccountPo.class)  @JoinColumn(name="report_verifier", referencedColumnName="account_id", nullable=false)  private AccountPo verifier;  @Temporal(TemporalType.TIMESTAMP)  @Column(name="report_creat_date")  private Date createDate;  @Temporal(TemporalType.TIMESTAMP)  @Column(name="report_publish_date")  private Date publishDate;  @Lob  @Column(name="report_content", nullable=false)  private String content;  @ManyToOne(targetEntity=CorporationPo.class)  @JoinColumn(name="corporation_id", referencedColumnName="corporation_id", nullable=false)  private CorporationPo corporation;  }

启动后发现hibernate没有自动创建report表,console没有报错信息。

hibernate版本如下图:
这里写图片描述

由于其他表都可以正确自动创建,因此排除hibernate配置错误的可能。

采用排除法依次注释report中的字段,直到发现若定义content字段hibernate就无法自动建表report,去掉content字段就可以正常建表。

再次测试发现,问题出在nullable=false。将其删除,或者修改为nullable=true均可正常建表。

  @Lob  @Column(name="report_content", nullable=true)  private String content;

  @Lob  @Column(name="report_content")  private String content;

那么问题来了,这个究竟是hibernate的bug,还是hibernate故意要求“不能强制longtext字段不能为null”?

+---------------------+--------------+------+-----+---------+-------+| Field               | Type         | Null | Key | Default | Extra |+---------------------+--------------+------+-----+---------+-------+| order_id            | int(11)      | NO   | PRI | NULL    |       || report_content      | longtext     | YES  |     | NULL    |       || corporation_id      | int(11)      | NO   | PRI | NULL    |       || report_creat_date   | datetime     | YES  |     | NULL    |       || report_publish_date | datetime     | YES  |     | NULL    |       || report_reporter     | int(11)      | NO   | PRI | NULL    |       || report_tester       | int(11)      | NO   | PRI | NULL    |       || report_title        | varchar(255) | YES  |     | NULL    |       || report_verifier     | int(11)      | NO   | PRI | NULL    |       |+---------------------+--------------+------+-----+---------+-------+
0 0
原创粉丝点击