我无法删除数据库中引用了“personen”的“Adresse”。我在'personen'上获得了参照完整性约束违规。 我想在调用em.remove(adresse)时删除'Adresse'及其'personen'。 为了实现这一点,我必须做什么,而不必先删除引用的“人物”?
重要代码部分:
模型
住址
@Id
@Column(name = "ADR_PK")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToMany(mappedBy = "adresse", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<PersonDetail2> personen;
PersonDetail2
@ManyToOne
@JoinColumn(name = "ADR_FK", referencedColumnName = "ADR_PK", nullable = false)
private Adresse adresse;
服务
持久性
public Adresse deleteAdresseWithId(Integer id) throws DetailException {
List<String> errorMessages = new ArrayList<String>();
Adresse adresse = em.find(Adresse.class, id);
if (adresse == null) {
throw new DetailException(errorMessages, Response.Status.NOT_FOUND);
}
log.debug("adresse found " + adresse.toString());
em.remove(adresse);
return adresse;
}
测试
恢复
@HttpTest(method = Method.POST, path = "persDB/rest/r/deleteAdresse/3", content = "{}", type = MediaType.APPLICATION_JSON)
public void deleteAdresseFound() {
Assert.assertEquals(200, response.getStatus());
}
堆栈跟踪
2014-01-27 11:17:43,312 [http-/0.0.0.0:8080-1] FINE org.jboss.resteasy.core.SynchronousDispatcher - PathInfo: r/deleteAdresse/1
2014-01-27 11:17:43,312 [http-/0.0.0.0:8080-1] FINE org.jboss.resteasy.cdi.CdiConstructorInjector - Beans found for class ch.saxer.persDB.service.PersRestService : [Managed Bean [class ch.saxer.persDB.service.PersRestService] with qualifiers [@Any @Default]]
2014-01-27 11:17:43,313 [http-/0.0.0.0:8080-1] DEBUG ch.saxer.persDB.service.PersJPA - delete adresse with id: 1
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.internal.SessionImpl - Opened session at timestamp: 13908178633
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - Skipping JTA sync registration due to auto join checking
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl - successfully registered Synchronization
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.ejb.AbstractEntityManagerImpl - Looking for a JTA transaction to join
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.jboss.as.jpa - http-/0.0.0.0:8080-1:[transaction scoped EntityManager]: created entity manager session TransactionImple < ac, BasicAction: 0:ffffa609125d:-2eb1ffe2:52e62875:ba status: ActionStatus.RUNNING >
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.jboss.as.jpa - http-/0.0.0.0:8080-1:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffffa609125d:-2eb1ffe2:52e62875:ba status: ActionStatus.RUNNING >
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.loader.Loader - Loading entity: [ch.saxer.persDB.model.Adresse#1]
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtaining JDBC connection
2014-01-27 11:17:43,314 [http-/0.0.0.0:8080-1] DEBUG org.jboss.jca.core.connectionmanager.pool.strategy.OnePool - java:jboss/datasources/persDBds: getConnection(null, WrappedConnectionRequestInfo@105d5aa[userName=root]) [1/20]
2014-01-27 11:17:43,315 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtained JDBC connection
2014-01-27 11:17:43,315 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.SQL -
select
adresse0_.ADR_PK as ADR1_18_0_,
adresse0_.ort as ort18_0_,
adresse0_.plz as plz18_0_
from
Adresse adresse0_
where
adresse0_.ADR_PK=?
2014-01-27 11:17:43,315 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.loader.Loader - Result set row: 0
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[ch.saxer.persDB.model.Adresse#1]
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Releasing JDBC connection
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Released JDBC connection
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler - HHH000163: Logical connection releasing its physical connection
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.internal.TwoPhaseLoad - Resolving associations for [ch.saxer.persDB.model.Adresse#1]
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.internal.TwoPhaseLoad - Done materializing entity [ch.saxer.persDB.model.Adresse#1]
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.internal.StatefulPersistenceContext - Initializing non-lazy collections
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.loader.Loader - Done entity load
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG ch.saxer.persDB.service.PersJPA - adresse found Adresse [id=1, plz=1234, ort=ort1]
2014-01-27 11:17:43,316 [http-/0.0.0.0:8080-1] DEBUG org.jboss.as.jpa - http-/0.0.0.0:8080-1:[transaction scoped EntityManager]: reuse entity manager session already in tx TransactionImple < ac, BasicAction: 0:ffffa609125d:-2eb1ffe2:52e62875:ba status: ActionStatus.RUNNING >
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Processing flush-time cascades
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Dirty checking collections
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.internal.Collections - Collection dereferenced: [ch.saxer.persDB.model.Adresse.personen#1]
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 1 deletions to 1 objects
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 1 removals to 1 collections
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.internal.util.EntityPrinter - Listing entities:
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.internal.util.EntityPrinter - ch.saxer.persDB.model.Adresse{id=1, personen=<uninitialized>, plz=1234, ort=ort1}
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtaining JDBC connection
2014-01-27 11:17:43,317 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtained JDBC connection
2014-01-27 11:17:43,318 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.SQL -
delete
from
Adresse
where
ADR_PK=?
2014-01-27 11:17:43,319 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171] [n/a]: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:414)
at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:431)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:307)
at org.h2.table.Table.fireConstraints(Table.java:873)
at org.h2.table.Table.fireAfterRow(Table.java:890)
at org.h2.command.dml.Delete.update(Delete.java:99)
at org.h2.command.CommandContainer.update(CommandContainer.java:75)
at org.h2.command.Command.executeUpdate(Command.java:230)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:334)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:150)
at java.lang.Thread.run(Unknown Source)
at org.h2.engine.SessionRemote.done(SessionRemote.java:568) [h2-1.3.171.jar:1.3.171]
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:181) [h2-1.3.171.jar:1.3.171]
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156) [h2-1.3.171.jar:1.3.171]
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142) [h2-1.3.171.jar:1.3.171]
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source) [:1.7.0_21]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_21]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_21]
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at com.sun.proxy.$Proxy65.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3134) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3337) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:100) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
etc.
2014-01-27 11:17:43,325 [http-/0.0.0.0:8080-1] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 23503, SQLState: 23503
2014-01-27 11:17:43,325 [http-/0.0.0.0:8080-1] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171]
2014-01-27 11:17:43,325 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Skipping aggressive release due to registered resources
2014-01-27 11:17:43,325 [http-/0.0.0.0:8080-1] DEBUG org.hibernate.ejb.AbstractEntityManagerImpl - Mark transaction for rollback
2014-01-27 11:17:43,325 [http-/0.0.0.0:8080-1] WARN com.arjuna.ats.arjuna - ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffa609125d:-2eb1ffe2:52e62875:bb, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@191b93e >: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1372) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1301) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1495) [hibernate-entitymanager-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:91) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:231) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:303) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:189) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:42) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:176) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final-redhat-1.jar:1.1.1.Final-redhat-1]
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at ch.saxer.persDB.interf.PersJPAInterface$$$view3.deleteAdresseWithId(Unknown Source) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_21]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_21]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_21]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_21]
at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:267) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:263) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:110) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at ch.saxer.persDB.service.PersJPAInterface$-1484255507$Proxy$_$$_Weld$Proxy$.deleteAdresseWithId(PersJPAInterface$-1484255507$Proxy$_$$_Weld$Proxy$.java) [classes:]
at ch.saxer.persDB.service.PersService.deleteAdresseWithId(PersService.java:64) [classes:]
at ch.saxer.persDB.service.PersRestService.deleteAdresseWithId(PersRestService.java:159) [classes:]
at ch.saxer.persDB.service.PersRestService$Proxy$_$$_WeldClientProxy.deleteAdresseWithId(PersRestService$Proxy$_$$_WeldClientProxy.java) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_21]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_21]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_21]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_21]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.1.Final-redhat-1.jar:1.0.1.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.8.Final-redhat-1.jar:1.1.8.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jet-jboss-web-custom-eap-1.0.14.jar:1.0.14]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Caused by: org.hibernate.exception.ConstraintViolationException: Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171]
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:128) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at com.sun.proxy.$Proxy65.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3134) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3337) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:100) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:280) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:104) [hibernate-core-4.1.3.Final-redhat-1.jar:4.1.3.Final-redhat-1]
... 79 more
Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK8E488775F35C0145: PUBLIC.PERSON FOREIGN KEY(ADR_FK) REFERENCES PUBLIC.ADRESSE(ADR_PK) (1)"; SQL statement:
delete from Adresse where ADR_PK=? [23503-171]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:414)
at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:431)
at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:307)
at org.h2.table.Table.fireConstraints(Table.java:873)
at org.h2.table.Table.fireAfterRow(Table.java:890)
at org.h2.command.dml.Delete.update(Delete.java:99)
at org.h2.command.CommandContainer.update(CommandContainer.java:75)
at org.h2.command.Command.executeUpdate(Command.java:230)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:334)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:150)
at java.lang.Thread.run(Unknown Source)
etc.
感谢您的时间
答案 0 :(得分:0)
@Chris谢谢,这就是问题所在。我有两个人员实体为同一个表人(PersonDetail1 / PersonDetail2)。当我选择Adresse引用PersonDetail2进行删除时,它没有来自PersonDetail1的引用表。所以我编写了一个引用所有表的第三个名为PersonDetail3的类。将Adresse更改为引用PersonDetail3而不是PersonDetail2并编程引用PersonDetail2的AdressDetail2。现在它没有任何问题。