msh*_*rir 7 annotations hibernate hibernate-annotations
在我的Web应用程序中,我有一个文本区域,其用户填充的内容最终通过Hibernate持久保存到db.我遇到了一个问题,当用户输入超过一定长度时,持久性就会失败.有没有办法通过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
Run Code Online (Sandbox Code Playgroud)
luc*_*cas 21
您可以在注释上使用length参数,如下所示:
@Column(length=1000)
Run Code Online (Sandbox Code Playgroud)
或者,如果您的数据库支持,您可以将列类型更改为类似文本,如下所示:
@Column(columnDefinition="text")
Run Code Online (Sandbox Code Playgroud)
如果您正在使用hbm2ddl update,则将创建该列以使用该类型(特定于数据库).
我有一个类似的问题,我通过将hibernate"text"类型分配给属性来解决:
@Type(type="text")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20595 次 |
| 最近记录: |