@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
- @Lob字段在@Column中使用nullable=false导致hibernate无法自动建表
- 使用新类型Nullable处理数据库表中null字段
- hibernate实体中@Column(name = "name",updatable=false)
- 在Hibernate中使用@lob修饰大数据类型的属性
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- 在C#中使用Nullable类型
- hibernate无法在mysql中自动建表解决办法
- hibernate无法在mysql中自动建表解决办法
- hibernate配置文件中重复定义导致的错误:should be mapped with insert="false" update="false"
- J2EE程序中使用oracle数据库LOB字段的总结
- Java程序中使用oracle数据库LOB字段的总结
- ORACLE中LOB字段的使用和维护
- ORACLE中LOB字段的使用和维护
- hibernate无法自动建表
- 在Django的Model中定义TextField字段导致无法在Mysql中生成表格
- 在Django的Model中定义TextField字段导致无法在Mysql中生成表格
- cf 675 A
- app 接口开发文档范例
- C++ STL--vector容器用法详解
- 百度地图
- Windows杀死进程
- @Lob字段在@Column中使用nullable=false导致hibernate无法自动建表
- GITHub创建和本机要连接需要创建公钥
- poj 2431
- 关于接口测试 下
- UVa 512 Spreadsheet Tracking
- STL之priority_queue
- 线程周期
- 解决AndroidStudio导入项目在 Building gradle project info 一直卡住
- 动画资源