Hibernate@Lob注释不再有效:不能用几个字符串超过CLOB的总长度



当我试图用@lob字符串持久化实体时,我遇到了一个错误。我记得那部分代码运行得很好,我根本不记得更改过它。我很困惑。以下是我对一个错误的处理:

错误30 04 12 23:50:31[org.hibernate.util.JDBCException Reporter]=>起始位置[1]不能超过CLOB总长度[0]com.vaadin.event.ListerMethod$MethodException原因:javax.persistence.PersistenceException:org.hubinate.exception.GenericJDBCException:无法插入:[life.domain_model.Post]com.vaadin.event.ListerMethod.rereceiveEvent(ListenerMethod.java:507)在com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1154)网址:com.vaadin.ui.Button.fireClick(Button.java:371)com.vaadin.ui.Button.changeVariables(Button.java:193)com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1094)在com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:590)在com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:266)在com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:476)在org.vaadin.navigator7.NavigableApplicationServlet.service(NavigableApplication Servlet.java:46)位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)在org.apache.catalina.core.StandardWrapperValv.invoke(StandardWrapperValve.java:233)在org.apache.catalina.core.StandardContextValv.invoke(StandardContextValv.java:191)在org.apache.catalina.core.StandardHostValv.invoke(StandardHostValve.java:127)在org.apache.catalina.vals.ErrorReportValve.ioke(ErrorReportValve.ja:102)在org.apache.catalina.core.StandardEngineValv.invoke(StandardEngineValv.java:109)在org.apache.catalina.connecter.CoyoteAdapter.service(Coyotedapter.java:298)在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)在org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)在org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)在java.lang.Thread.run(未知源)由以下原因引起:javax.persistence.PersistenceException:org.hubinate.exception.GenericJDBCException:无法插入:[life.domain_model.Post]org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)在org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)在org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)在org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:695)位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于的sun.reflect.NativeMethodAccessorImpl.invoke(未知源)位于的sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)位于的java.lang.reflect.Method.ioke(未知源)org.springframework.om.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreater.java:240)在$Proxy29.merge(未知源)life.dao.ForumDao.merge(ForumDao.java:24)life.dao.ForumDao$$FastClassByCGLIB$$6eb7cb5f.invoke()net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)org.springframework.aop.framework.Cglib2OpProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2OpProxy.java:688)在org.springframework.aop.framework.ReflectiveMethodInvocation.prough(ReflectiveMethodInvocation.java:150)在org.springframework.transaction.interceptor.TransactionInterceptor.ioke(TransactionInterceptor.java:110)在org.springframework.aop.framework.ReflectiveMethodInvocation.prough(ReflectiveMethodInvocation.java:172)在org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.cintercept(Cglib2aop:621)在life.dao.ForumDao$$EnhancerByCGLIB$$8ecd1fd.merge()在life.dao.ForumDaoImpl.mergeDiscussion(ForumDaoImpl.java:29)life.dao.ForumDaoImpl.saveNewPostForDiscussion(ForumDaoImpl.java:50)在life.dao.ForumDaoImpl$$FastClassByCGLIB$$6d37da1f.invoke()在net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)org.springframework.aop.framework.Cglib2OpProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2OpProxy.java:688)在org.springframework.aop.framework.ReflectiveMethodInvocation.prough(ReflectiveMethodInvocation.java:150)在org.springframework.transaction.interceptor.TransactionInterceptor.ioke(TransactionInterceptor.java:110)在org.springframework.aop.framework.ReflectiveMethodInvocation.prough(ReflectiveMethodInvocation.java:172)在org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.cintercept(Cglib2aop:621)在life.dao.ForumDaoImpl$$EnhancerByCGLIB$$66b0b0bd.saveNewPostForDiscussion()在life.ui.layouts.ForumEditorLayout.replyToDiscussion(论坛编辑器布局.java:112)在life.ui.layouts.ForumEditorLayout$3.buttonClick(ForumEditor Layout.java:84)位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于的sun.reflect.NativeMethodAccessorImpl.invoke(未知源)位于的sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)位于的java.lang.reflect.Method.ioke(未知源)com.vaadin.event.ListerMethod.rereceiveEvent(ListenerMethod.java:487)…22更多原因:org.hubinate.exception.GenericJDBCException:无法在处插入:[life.domain_model.Post]org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)在org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningdelete.java:64)在org.hibernate。persister.entity.AbstractEntityPersister.insert(AbstractEntityPersester.java:2327)在org.hibernate。persister.entity.AbstractEntityPersister.insert(AbstractEntityPersester.java:2834)在org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)在org.hibernate.engine.ActionQueue.execure(ActionQueue.java:273)org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)在org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)在org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)在org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:62)在org.hibernate.event.def.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEvent Listener.java:415)在org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEvent Listener.java:341)在org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEvent Listener.java:303)在org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEvent Listener.java:258)位于org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:877)org.hibernate.impl.SessionImpl.merge(SessionImpl.java:859)org.hibernate.engine.CastingAction$6.cacade(CascadingAction.java:279)位于org.hibernate.engine.CastcadeToOne(Cascade.java:392)org.hibernate。engine.Castcade.cascadeAssociation(Cascade.java:335)org.hibernate.engine.Castcade.cascadeProperty(Cascade.java:204)org.hibernate。engine.Castcade.cascadeCollectionElements(Cascade.java:425)网址:org.hibernate.engine.CastcadeCollection(Cascade.java:362)网址:org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)位于org.hibernate.engine.Castcade.cascadeProperty(Cascade.java:204)org.hibernate.engine.Castcade.Cascade(Cascade.java:161)org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEvent Listener.java:630)在org.hibernate.event.def.DefaultMergeEventListener.entityIsDetailed(DefaultMergeEvent Listener.java:490)在org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEvent Listener.java:255)在org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEvent Listener.java:84)位于org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686)…54更多原因:java.sql.sql异常:起始位置[1]不能超过处的CLOB总长度[0]org.hibernate.engine.jdbc.ClobProxy.invoke(ClobProxy.java:146)位于的$Proxy36.getSubString(未知源)com.mysql.jdbc.PreparedStatement.setClob(PreparedStatements.java:3553)在org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedSStatement.java:187)在org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedSStatement.java:187)在org.hibernate.type.descriptor.sql.ClobTypeDescriptor$1.doBind(ClobTypeDescriptor.java:60)在org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)在org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasic type.java:282)在org.hibernate.type.AbstractStandardBasicType.nullSafeSet(抽象标准基本类型.java:277)在org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85)在org.hibernate。persister.entity.AbstractEntityPersister.脱水(AbstractEntityPersester.java:2166)在org.hibernate。persister.entity.AbstractEntityPersister.脱水(AbstractEntityPersester.java:2143)在org.hibernate。persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersester.java:2321)在org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningdelete.java:56)…还有85个

这是Post实体:

@Entity
public class Post {
@Id @GeneratedValue
private Long id;
@ManyToOne @JoinColumn(name = "owner_id")
private User owner;
@ManyToOne @JoinColumn(name = "editer_id")
private User lastEditer;
private Date creationDate;
private Date lastEditionDate;
@Lob
private String content;
@ManyToOne @JoinColumn(name = "discussion_id")
private Discussion discussion;
public Post(){
}
public Post(User owner,String content){
this.owner = owner;
this.lastEditer = null;
Date curent = new Date();
this.creationDate = curent;
this.lastEditionDate = curent;
this.content = content;
this.discussion = null;
}

//G&S
....

无论字符串内容长度如何,我都会得到错误。我仍然在使用hibernate 3.6.0和MySql 5.5(+spring)。有人能告诉我如何纠正吗?

我在尝试将空字符串保存到用@Lob注释的字段时遇到了同样的问题。发现此错误提示:https://hibernate.onjira.com/browse/HHH-5704

我的项目隐式地包含了Hibernate核心版本3.6.0,一旦我更新了POM以显式地包含核心版本3.6.10,它就开始按预期工作了。

这张票很好地解释了这个问题。

相关内容

  • 没有找到相关文章

最新更新