1

我正在尝试使用 JPA 2(使用 Hibernate)与有序多端(使用 List)建立双向关系。

基于以下问题报告的问题@OneToMany(mappedBy
Hibernate 3.5 中的 JPA 2.0 @OrderColumn 注释

https://hibernate.onjira.com/browse/HHH-5732

我尝试了不同的方法,建议在:http:
//josian.wordpress.com/2006/09/09/hibernate-annotations-bidirectional-one-to-many/

但是,在持久化数据时,我遇到了异常。

考虑以下实体类:

@Entity
public class Schedule implements Serializable {
    private List<Presentation> presentations;
    private String name = null;

    ...

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn (name = "SCHEDULE_NAME")
    @IndexColumn(name = "PRESENTATION_POSITION")
    public List<Presentation> getPresentations() {
        return presentations;
    }

    @Id
    @NotNull
    @Index(name = "ScheduleNameIdx")
    @Column(name = "SCHEDULE_NAME")
    public String getName() {
        return name;
    }

...
}

@Entity
public class Presentation implements Serializable {
    private Long id;
    private Schedule schedule;

    ...

    @Id
    @GeneratedValue
    @Index(name = "PresentationIdIdx")
    @Column(name = "PRESENTATION_ID")
    public Long getId() {
        return id;
    }

    @ManyToOne(optional = false)
    @JoinColumn(name="SCHEDULE_NAME", nullable = false, updatable = false, insertable = false)
    public Schedule getSchedule() {
        return schedule;
    }
...
}

我得到的例外是:

07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.h.util.JDBCExceptionReporter - could not insert: [com.google.code.yourpresenter.entity.Presentation] [insert into Presentation (PRESENTATION_ID, bgImage_id, media_id, name, song_id) values (default, ?, ?, ?, ?)]
java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10066 table: PRESENTATION column: SCHEDULE_NAME
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) ~[hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2345) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2852) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:62) [hibernate-entitymanager-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:415) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:341) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:877) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:859) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:279) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.engine.Cascade.cascade(Cascade.java:161) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:630) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:490) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:255) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855) [hibernate-core-3.6.7.Final.jar:3.6.7.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686) [hibernate-entitymanager-3.6.7.Final.jar:3.6.7.Final]
    at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_15]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_15]
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at $Proxy34.merge(Unknown Source) [na:na]
    at com.google.code.yourpresenter.service.ScheduleServiceImpl.persist(ScheduleServiceImpl.java:71) [classes/:na]
    at com.google.code.yourpresenter.service.ScheduleServiceImpl.addPresentation(ScheduleServiceImpl.java:122) [classes/:na]
    at com.google.code.yourpresenter.service.ScheduleServiceImpl$$FastClassByCGLIB$$52d414d3.invoke(<generated>) [cglib-2.2.2.jar:na]
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [cglib-2.2.2.jar:na]
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) [spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) [spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at com.google.code.yourpresenter.service.ScheduleServiceImpl$$EnhancerByCGLIB$$9dfe2fc9.addPresentation(<generated>) [cglib-2.2.2.jar:na]
    at com.google.code.yourpresenter.view.ScheduleView.dropped(ScheduleView.java:154) [classes/:na]
    at com.google.code.yourpresenter.view.ScheduleView.dropped(ScheduleView.java:92) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_15]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_15]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_15]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_15]
    at com.sun.el.parser.AstValue.invoke(AstValue.java:187) [jsp-2.1-glassfish-2.1.v20091210.jar:na]
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297) [jsp-2.1-glassfish-2.1.v20091210.jar:na]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at org.richfaces.event.MethodExpressionDropListener.processDrop(MethodExpressionDropListener.java:45) [richfaces-components-ui-4.2.2.Final.jar:4.2.2.Final]
    at org.richfaces.event.DropEvent.processListener(DropEvent.java:69) [richfaces-components-api-4.2.2.Final.jar:4.2.2.Final]
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) [jsf-api-2.1.0.jar:2.1.0-FCS]
    at org.richfaces.component.AbstractDropTarget.broadcast(AbstractDropTarget.java:123) [richfaces-components-ui-4.2.2.Final.jar:4.2.2.Final]
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jsf-api-2.1.0.jar:2.1.0-FCS]
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jsf-api-2.1.0.jar:2.1.0-FCS]
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409) [jsf-api-2.1.0.jar:2.1.0-FCS]
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221) [jetty-6.1.26.jar:6.1.26]
    at com.google.code.yourpresenter.filter.ScheduleSelectedFilter.doFilter(ScheduleSelectedFilter.java:47) [classes/:na]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212) [jetty-6.1.26.jar:6.1.26]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.Server.handle(Server.java:326) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) [jetty-6.1.26.jar:6.1.26]
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) [jetty-util-6.1.26.jar:6.1.26]
Caused by: org.hsqldb.HsqlException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10066 table: PRESENTATION column: SCHEDULE_NAME
    at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.Table.enforceRowConstraints(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.Table.insertSingleRow(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.StatementDML.insertRowSet(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.StatementInsert.getResult(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.StatementDMQL.execute(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    at org.hsqldb.Session.execute(Unknown Source) ~[hsqldb-2.2.6.jar:2.2.6]
    ... 96 common frames omitted
07:39:43.265 [12937429@qtp-9708927-7] WARN  o.h.util.JDBCExceptionReporter - SQL Error: -10, SQLState: 23502
07:39:43.265 [12937429@qtp-9708927-7] ERROR o.h.util.JDBCExceptionReporter - integrity constraint violation: NOT NULL check constraint; SYS_CT_10066 table: PRESENTATION column: SCHEDULE_NAME
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.h.ejb.AbstractEntityManagerImpl - mark transaction for rollback
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.s.orm.jpa.JpaTransactionManager - Initiating transaction rollback
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.s.orm.jpa.JpaTransactionManager - Rolling back JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@b840d2]
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.h.transaction.JDBCTransaction - rollback
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.h.transaction.JDBCTransaction - re-enabling autocommit
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.h.transaction.JDBCTransaction - rolled back JDBC Connection
07:39:43.265 [12937429@qtp-9708927-7] DEBUG org.hibernate.jdbc.ConnectionManager - aggressively releasing JDBC connection
07:39:43.265 [12937429@qtp-9708927-7] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.s.orm.jpa.JpaTransactionManager - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@b840d2] after transaction
07:39:43.265 [12937429@qtp-9708927-7] DEBUG o.s.o.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
19.8.2012 7:39:43 com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /presenter/presenter.xhtml @302,44 dropListener="#{scheduleView.dropped}": org.springframework.dao.DataIntegrityViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]; SQL [insert into Presentation (PRESENTATION_ID, bgImage_id, media_id, name, song_id) values (default, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]
javax.el.ELException: /presenter/presenter.xhtml @302,44 dropListener="#{scheduleView.dropped}": org.springframework.dao.DataIntegrityViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]; SQL [insert into Presentation (PRESENTATION_ID, bgImage_id, media_id, name, song_id) values (default, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
    at org.richfaces.event.MethodExpressionDropListener.processDrop(MethodExpressionDropListener.java:45)
    at org.richfaces.event.DropEvent.processListener(DropEvent.java:69)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
    at org.richfaces.component.AbstractDropTarget.broadcast(AbstractDropTarget.java:123)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
    at com.google.code.yourpresenter.filter.ScheduleSelectedFilter.doFilter(ScheduleSelectedFilter.java:47)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: org.springframework.dao.DataIntegrityViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]; SQL [insert into Presentation (PRESENTATION_ID, bgImage_id, media_id, name, song_id) values (default, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:641)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    at com.google.code.yourpresenter.service.ScheduleServiceImpl$$EnhancerByCGLIB$$9dfe2fc9.addPresentation(<generated>)
    at com.google.code.yourpresenter.view.ScheduleView.dropped(ScheduleView.java:154)
    at com.google.code.yourpresenter.view.ScheduleView.dropped(ScheduleView.java:92)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    ... 35 more
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.google.code.yourpresenter.entity.Presentation]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2345)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2852)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
    at org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:62)
    at org.hibernate.event.def.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:415)
    at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:341)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258)
    at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:877)
    at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:859)
    at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:279)
    at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
    at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
    at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425)
    at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
    at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
    at 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)
    at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:490)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:255)
    at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
    at 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)
    at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    at $Proxy34.merge(Unknown Source)
    at com.google.code.yourpresenter.service.ScheduleServiceImpl.persist(ScheduleServiceImpl.java:71)
    at com.google.code.yourpresenter.service.ScheduleServiceImpl.addPresentation(ScheduleServiceImpl.java:122)
    at com.google.code.yourpresenter.service.ScheduleServiceImpl$$FastClassByCGLIB$$52d414d3.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
    ... 49 more
Caused by: java.sql.SQLIntegrityConstraintViolationException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10066 table: PRESENTATION column: SCHEDULE_NAME
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
    ... 92 more
Caused by: org.hsqldb.HsqlException: integrity constraint violation: NOT NULL check constraint; SYS_CT_10066 table: PRESENTATION column: SCHEDULE_NAME
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.Table.enforceRowConstraints(Unknown Source)
    at org.hsqldb.Table.insertSingleRow(Unknown Source)
    at org.hsqldb.StatementDML.insertRowSet(Unknown Source)
    at org.hsqldb.StatementInsert.getResult(Unknown Source)
    at org.hsqldb.StatementDMQL.execute(Unknown Source)
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 96 more
4

4 回答 4

0

在您的 Presentation 实体中,将 getSchedule() 的 insertable 和 updateble 属性更改为true。见下文;

   @ManyToOne(optional = false)
   @JoinColumn(name="SCHEDULE_NAME", nullable =false, updatable = true, insertable = true)
   public Schedule getSchedule() {
      return schedule;
   }
于 2012-08-20T07:03:15.213 回答
0

对于你的persist策略,hibernate会先将记录插入'Presentation'表,然后更新它的'schedule_id',但是你设置schedule_id不为null,所以插入会失败。

一种解决方案是删除“非空”约束。</p>

第二种方案是重新设计关系配置,让hibernate只执行一个插入语句(包括'schedule_id'),不需要更新

于 2012-08-19T16:04:09.730 回答
0

删除@NotNull。非关键字段不允许空值。考虑输入数据。

于 2012-08-19T11:36:12.763 回答
0

为什么要updatable = false, insertable = falsePresentationtoSchedule映射中指定?

当然,这个值需要是可插入和可更新的以维持关系。尝试删除它,您应该在尝试插入时看到 SQL 更改。

于 2012-08-19T13:41:16.690 回答