在我的 Web 应用程序中,我有一个文本区域,其用户填充的内容最终通过 Hibernate 持久保存到数据库中。我遇到了一个问题,当用户输入超过一定长度时,持久化失败。有没有办法通过 Hibernate Annotations 或在配置中指示该特定字段应该支持更长的字符串,并且数据库列类型应该反映这一点?
这是我得到的异常:
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'introText' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2007)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1443)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 41 more
您可以在注释上使用长度参数,如下所示:
@Column(length=1000)
或者,如果您的数据库支持,您可以将列类型更改为类似文本的类型,如下所示:
@Column(columnDefinition="text")
如果您使用 hbm2ddl 更新,则将创建列以使用该类型(特定于数据库)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)