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

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

@Embeddable
public 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
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值