当我尝试使用@lob String保持实体时出错。我记得部分代码运行良好,我根本不记得改变它。我很迷惑。以下是我对错误的看法:
ERROR 30 04 12 23:50:31 [org.hibernate.util.JDBCExceptionReporter] => 起始位置[1]不能超过整体CLOB长度[0] com.vaadin.event.ListenerMethod $ MethodException原因: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException:无法插入: [life.domain_model.Post] at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507) 在com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1154) 在com.vaadin.ui.Button.fireClick(Button.java:371)at com.vaadin.ui.Button.changeVariables(Button.java:193)at 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(NavigableApplicationServlet.java:46) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.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.hibernate.exception.GenericJDBCException:无法插入: [life.domain_model.Post] at 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) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at org.springframework.orm.jpa.SharedEntityManagerCreator $ SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 在$ Proxy29.merge(未知来源)at life.dao.ForumDao.merge(ForumDao.java:24)at life.dao.ForumDao $$ FastClassByCGLIB $$ 6eb7cb5f.invoke()at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)at at org.springframework.aop.framework.Cglib2AopProxy $ CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 在 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 在 org.springframework.aop.framework.Cglib2AopProxy $ DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at life.dao.ForumDao $$ EnhancerByCGLIB $$ 8ecdd1fd.merge() 在life.dao.ForumDaoImpl.mergeDiscussion(ForumDaoImpl.java:29)at at life.dao.ForumDaoImpl.saveNewPostForDiscussion(ForumDaoImpl.java:50) 在 life.dao.ForumDaoImpl $$ FastClassByCGLIB $$ 6d37da1f.invoke() 在net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)at org.springframework.aop.framework.Cglib2AopProxy $ CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 在 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 在 org.springframework.aop.framework.Cglib2AopProxy $ DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) 在 life.dao.ForumDaoImpl $$ EnhancerByCGLIB $$ 66b0b0bd.saveNewPostForDiscussion() 在 life.ui.layouts.ForumEditorLayout.replyToDiscussion(ForumEditorLayout.java:112) 在 life.ui.layouts.ForumEditorLayout $ 3.buttonClick(ForumEditorLayout.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487) ... 22更多引起:org.hibernate.exception.GenericJDBCException: 无法插入:[life.domain_model.Post] at 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(AbstractReturningDelegate.java:64) 在 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2327) 在 org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834) 在 org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) 在org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)at at 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(DefaultMergeEventListener.java:415) 在 org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:341) 在 org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303) 在 org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258) 在org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:877)at at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:859)at org.hibernate.engine.CascadingAction $ 6.cascade(CascadingAction.java:279) 在org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)at at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)at at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425) 在org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362) 在org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338) 在org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)at org.hibernate.engine.Cascade.cascade(Cascade.java:161)at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:630) 在 org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:490) 在 org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:255) 在 org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) 在org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686) ... 54更多引起:java.sql.SQLException:起始位置[1] 不能超过整体CLOB长度[0] at org.hibernate.engine.jdbc.ClobProxy.invoke(ClobProxy.java:146)at at $ Proxy36.getSubString(未知来源)at com.mysql.jdbc.PreparedStatement.setClob(PreparedStatement.java:3553) 在 org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.java:187) 在 org.apache.commons.dbcp.DelegatingPreparedStatement.setClob(DelegatingPreparedStatement.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(AbstractStandardBasicType.java:282) 在 org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277) 在 org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85) 在 org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166) 在 org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2143) 在 org.hibernate.persister.entity.AbstractEntityPersister $ 4.bindValues(AbstractEntityPersister.java:2321) 在 org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.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
....
无论String内容长度如何,我都会收到错误。我还在使用hibernate 3.6.0和MySql 5.5(+ spring)。有谁能告诉我如何纠正这个问题?
答案 0 :(得分:2)
在尝试将空字符串保存到使用@Lob注释的字段时遇到了同样的问题。发现此错误:https://hibernate.onjira.com/browse/HHH-5704
我的项目隐含地包含了Hibernate核心版本3.6.0,一旦我更新了POM以明确包含核心版本3.6.10,它就开始按预期工作了。
票证很好地解释了问题。