获取异常java.sql.BatchUpdateException:数据截断:列'XXXX'的数据太长

时间:2013-02-07 08:53:55

标签: model liferay portlet liferay-6 sqlexception

我在liferay6中有我的自定义portlet,我在数据库中插入长数据时遇到异常java.sql.BatchUpdateException: Data truncation: Data too long for column 'XXXX' at row 1

即使我在portlet-modal-hints

中提供了以下参数,也会发生这种情况
<field name="advurl" type="String">
    <hint name="max-length">4000</hint>
</field>

这是抛出错误的列中的字符串:http://www.coderanch.com/t/435635/java/java/Regular-expression-check-specific-special

任何人都可以告诉我为什么这仍然是一个错误?

错误堆栈

Caused by: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.DataException: Could not execute JDBC batch update
    at com.liferay.portal.dao.orm.hibernate.ExceptionTranslator.translate(ExceptionTranslator.java:30)
    at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:122)
    at com.liferay.portal.kernel.dao.orm.ClassLoaderSession.flush(ClassLoaderSession.java:218)
    at com.liferay.portal.service.persistence.BatchSessionImpl.update(BatchSessionImpl.java:95)
    at com.liferay.portal.service.persistence.BatchSessionUtil.update(BatchSessionUtil.java:50)
    at emenu.advertise.database.service.persistence.advertisePersistenceImpl.updateImpl(advertisePersistenceImpl.java:505)
    ... 178 more
Caused by: org.hibernate.exception.DataException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:119)
    ... 182 more
Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'advlink' at row 1
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    ... 188 more

任何人都可以给我一些建议吗?

2 个答案:

答案 0 :(得分:4)

将我的comment转换为答案以解决此问题: - )

您应该在portal-model-hints.xml文件更改后重建服务。

然后你应该重新部署插件portlet以使更改生效。

因此请在执行上述步骤后检查数据库列是否已更新。

答案 1 :(得分:0)

当您使用service.xml创建的表(字段长度)与您提交的表不同时,会出现此错误。

您可以尝试使用属性maxlength =“4000”限制文本框或文本区域 这不会让你发布超过4000个单词。