持续期长字符串与Hibernate [英] Issue persisting long strings with Hibernate

查看:209
本文介绍了持续期长字符串与Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web应用程序,我有一个文本区域,其用户填充的内容最终保存到与Hibernate的分贝。我已运行到的一个问题是,当所述用户输入是超出一定的长度,持久性失败。有没有办法通过Hibernate注解,或者在配置,以表明这一特定领域应该支持更长的字符串,并且该数据库列类型应该反映这一点?

下面是我得到异常:

 产生的原因:java.sql.BatchUpdateException:数据截断:数据太长在行1'introText列
    在com.mysql.jdbc preparedStatement.executeBatchSerially(preparedStatement.java:2007)。
    在com.mysql.jdbc preparedStatement.executeBatch(preparedStatement.java:1443)。
    在org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    在org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    ...... 41多


解决方案

您可以使用长度参数上注释,像这样:

  @Column(长度= 1000)

或者你可以,如果你的数据库支持的话,像这样列类型更改为类似文本:

  @Column(columnDefinition =文本)

如果您使用的是先得用hbm2ddl更新,列将创建使用该类型代替(数据库特定)。

In my web application, I have a text area whose user-filled contents are ultimately persisted to the db with Hibernate. I have been running into an issue that when the user input is beyond a certain length, the persistence fails. Is there a way to indicate through Hibernate Annotations or in the configuration that this particular field should support longer strings, and that the database column type should reflect this?

Here's the exception that I'm getting:

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

解决方案

You could use the length parameter on the annotation, like so:

@Column(length=1000)

or you could change the column type to something like text if your database supports it, like so:

@Column(columnDefinition="text")

If you are using hbm2ddl update, and the column will be created to use that type instead (database specific).

这篇关于持续期长字符串与Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆