title: Deleting data from database using EntityManager causes violating referential integrity
body: <p>I am trying to remove data from by database, using the <code>javax.persistence.EntityManager</code>. This is a class diagram of the specific extract of my application:</p>
  
  <p><a href="https://i.stack.imgur.com/oGH3w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oGH3w.png" alt="Class diagram"></a></p>
  
  <p>I have a model class <code>WorkOrder</code>, which contains a <code>Specimen</code>. I am able to create new <code>WorkOrder</code>s and <code>Specimen</code>s and add them to my database. The tables <code>WORKORDER</code>, <code>SPECIMEN</code> and <code>WORKORDER_SPECIMEN</code> are then created by JPA automatically. The code is really simple:</p>
  
  <pre><code>public String newWorkOrder() {
      workOrderCurrent = new WorkOrder();
      return "new_work_order?faces-redirect=true";
  }
  
  public String newSpecimen() {
      specimenCurrent = new Specimen();
      return "new_specimen?faces-redirect=true";
  }
  </code></pre>
  
  <p>This is the way I persist <code>WorkOrder</code> and <code>Specimen</code>:</p>
  
  <pre><code>public String saveWorkOrder() {
      try {
          utx.begin();
          workOrderCurrent = em.merge(workOrderCurrent);
          em.persist(workOrderCurrent);
          workOrdersList.setWrappedData(em.createNamedQuery("SelectWorkOrders").getResultList());
          utx.commit();
      } catch (NotSupportedException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      } catch (SecurityException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (RollbackException e) {
          e.printStackTrace();
      } catch (HeuristicMixedException e) {
          e.printStackTrace();
      } catch (HeuristicRollbackException e) {
          e.printStackTrace();
      }
      return "work_orders_overview?faces-redirect=true";
  }
  
  public String saveSpecimen() {
      this.workOrderCurrent.getSpecimens().add(specimenCurrent);
      try {
          utx.begin();
          workOrderCurrent = em.merge(workOrderCurrent);
          em.persist(workOrderCurrent);
          workOrdersList.setWrappedData(em.createNamedQuery("SelectWorkOrders").getResultList());
          utx.commit();
      } catch (NotSupportedException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      } catch (SecurityException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (RollbackException e) {
          e.printStackTrace();
      } catch (HeuristicMixedException e) {
          e.printStackTrace();
      } catch (HeuristicRollbackException e) {
          e.printStackTrace();
      }
      return "specimens_overview?faces-redirect=true";
  }
  </code></pre>
  
  <p>I am also able to delete <code>WorkOrder</code>s, even if they contain <code>Specimen</code>s. Code:</p>
  
  <pre><code>public String deleteWorkOrder() {
      try {
          utx.begin();
      } catch (NotSupportedException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      }
      workOrderCurrent = workOrdersList.getRowData();
      workOrderCurrent = em.merge(workOrderCurrent);
      em.remove(workOrderCurrent);
      workOrdersList.setWrappedData(em.createNamedQuery("SelectWorkOrders").getResultList());
      try {
          utx.commit();
      } catch (SecurityException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (RollbackException e) {
          e.printStackTrace();
      } catch (HeuristicMixedException e) {
          e.printStackTrace();
      } catch (HeuristicRollbackException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      }
      return "work_orders_overview?faces-redirect=true";
  }
  </code></pre>
  
  <p>In a next step, I am trying to delete just a <code>Specimen</code> from a <code>WorkOrder</code>. Code:</p>
  
  <pre><code>public String deleteSpecimen() {
      try {
          utx.begin();
      } catch (NotSupportedException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      }
      specimenCurrent = specimensList.getRowData();
      specimenCurrent = em.merge(specimenCurrent);
      em.remove(specimenCurrent);
      specimensList.setWrappedData(em.createNamedQuery("SelectSpecimens").getResultList());
      try {
          utx.commit();
      } catch (SecurityException e) {
          e.printStackTrace();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (RollbackException e) {
          e.printStackTrace();
      } catch (HeuristicMixedException e) {
          e.printStackTrace();
      } catch (HeuristicRollbackException e) {
          e.printStackTrace();
      } catch (SystemException e) {
          e.printStackTrace();
      }
      return "specimens_overview?faces-redirect=true";
  }
  </code></pre>
  
  <p>When calling the <code>deleteSpecimen()</code> method, I get the following error:</p>
  
  <pre><code>09:38:20,661 INFO  [stdout] (default task-20) Hibernate: select specimen0_.id as id1_5_5_, specimen0_.fiber_id as fiber_id2_5_5_, specimen0_.gelcoat_id as gelcoat_3_5_5_, specimen0_.hardener_id as hardener4_5_5_, specimen0_.holeFilm_id as holeFilm5_5_5_, specimen0_.releaseAgent_id as releaseA6_5_5_, specimen0_.workOrder_id as workOrde7_5_5_, fiber1_.id as id1_0_0_, fiber1_.chargeNr as chargeNr2_0_0_, fiber1_.description as descript3_0_0_, fiber1_.manufacturer as manufact4_0_0_, fiber1_.surfaceWeight as surfaceW5_0_0_, fiber1_.type as type6_0_0_, gelcoat2_.id as id1_1_1_, gelcoat2_.chargeNr as chargeNr2_1_1_, gelcoat2_.description as descript3_1_1_, gelcoat2_.manufacturer as manufact4_1_1_, hardener3_.id as id1_2_2_, hardener3_.chargeNr as chargeNr2_2_2_, hardener3_.description as descript3_2_2_, hardener3_.hardnessType as hardness4_2_2_, hardener3_.manufacturer as manufact5_2_2_, holefilm4_.id as id1_3_3_, holefilm4_.chargeNr as chargeNr2_3_3_, holefilm4_.description as descript3_3_3_, holefilm4_.manufacturer as manufact4_3_3_, releaseage5_.id as id1_4_4_, releaseage5_.chargeNr as chargeNr2_4_4_, releaseage5_.description as descript3_4_4_, releaseage5_.manufacturer as manufact4_4_4_ from Specimen specimen0_ left outer join Fiber fiber1_ on specimen0_.fiber_id=fiber1_.id left outer join Gelcoat gelcoat2_ on specimen0_.gelcoat_id=gelcoat2_.id left outer join Hardener hardener3_ on specimen0_.hardener_id=hardener3_.id left outer join HoleFilm holefilm4_ on specimen0_.holeFilm_id=holefilm4_.id left outer join ReleaseAgent releaseage5_ on specimen0_.releaseAgent_id=releaseage5_.id where specimen0_.id=?
  
  09:38:20,669 INFO  [stdout] (default task-20) Hibernate: delete from Specimen where id=?
  
  09:38:20,671 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-20) SQL Error: 23503, SQLState: 23503
  09:38:20,671 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-20) Referentielle Integrität verletzt: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"
  Referential integrity constraint violation: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"; SQL statement:
  delete from Specimen where id=? [23503-173]
  09:38:20,673 INFO  [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (default task-20) HHH000010: On release of batch it still contained JDBC statements
  09:38:20,674 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-20) #{mbWorkOrderController.deleteSpecimen(Specimen)}: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement: javax.faces.FacesException: #{mbWorkOrderController.deleteSpecimen(Specimen)}: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIData.broadcast(UIData.java:1108)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      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:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
      at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      ... 35 more
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
      at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
      at de.fraunhofer.iwes.controller.WorkOrderController.deleteSpecimen(WorkOrderController.java:269)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
      at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
      at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:286)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
      ... 36 more
  Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3400)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3630)
      at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:114)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
      at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:67)
      at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1227)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1293)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
      at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
      at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
      ... 52 more
  Caused by: org.h2.jdbc.JdbcSQLException: Referentielle Integrität verletzt: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"
  Referential integrity constraint violation: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"; SQL statement:
  delete from Specimen where id=? [23503-173]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
      at org.h2.message.DbException.get(DbException.java:171)
      at org.h2.message.DbException.get(DbException.java:148)
      at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:421)
      at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:438)
      at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:314)
      at org.h2.table.Table.fireConstraints(Table.java:880)
      at org.h2.table.Table.fireAfterRow(Table.java:897)
      at org.h2.command.dml.Delete.update(Delete.java:100)
      at org.h2.command.CommandContainer.update(CommandContainer.java:79)
      at org.h2.command.Command.executeUpdate(Command.java:235)
      at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:154)
      at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:140)
      at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:537)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
      ... 65 more
  
  09:38:20,679 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-20) javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIData.broadcast(UIData.java:1108)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      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:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
      at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
      at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
      at de.fraunhofer.iwes.controller.WorkOrderController.deleteSpecimen(WorkOrderController.java:269)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at javax.el.ELUtil.invokeMethod(ELUtil.java:308)
      at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
      at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:286)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
      ... 36 more
  Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
      at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3400)
      at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3630)
      at org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:114)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
      at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:67)
      at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1227)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1293)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
      at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
      at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
      ... 52 more
  Caused by: org.h2.jdbc.JdbcSQLException: Referentielle Integrität verletzt: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"
  Referential integrity constraint violation: "FK_DW0025YHI9UYOL04FFU8OR0JY: PUBLIC.WORKORDER_SPECIMEN FOREIGN KEY(SPECIMENS_ID) REFERENCES PUBLIC.SPECIMEN(ID) (3)"; SQL statement:
  delete from Specimen where id=? [23503-173]
      at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
      at org.h2.message.DbException.get(DbException.java:171)
      at org.h2.message.DbException.get(DbException.java:148)
      at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:421)
      at org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:438)
      at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:314)
      at org.h2.table.Table.fireConstraints(Table.java:880)
      at org.h2.table.Table.fireAfterRow(Table.java:897)
      at org.h2.command.dml.Delete.update(Delete.java:100)
      at org.h2.command.CommandContainer.update(CommandContainer.java:79)
      at org.h2.command.Command.executeUpdate(Command.java:235)
      at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:154)
      at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:140)
      at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:537)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
      ... 65 more
  
  09:38:20,681 ERROR [org.jboss.as.txn] (default task-20) WFLYTX0003: APPLICATION ERROR: transaction still active in request with status 1
  </code></pre>
  
  <p>Which means I am violating referential integrity. What am I doing wrong?</p>