I am seeing unexpected behavior with Cascades on relationships with
repositories with DeltaSpike.
I have tried with both v1.4.1 and v1.4.0
I have two entities
Booking and Adventure
Booking has a OneToOne Relationship with Adventure with a CacadeType =
REFRESH
*@OneToOne(cascade = CascadeType.REFRESH)*
@JoinColumn(name = "ADVENTURE_NAME", referencedColumnName = "
ADVENTURE_NAME ")
private Adventure adventure;
I have a unit test to test that I cannot create a Booking for an adventure
that does not exist in the database.
*@Test*
public void cannotCreateNewAdventureFromBooking() throws Exception {
Booking booking = new Booking ();
Adventure adventure = new Adventure ("test");
booking.setAdventure(adventure);
this.bookingRepository.save(booking);
this.bookingRepository.flush();
}
I expect the test to fail with IllegalStateException that JPA throws, but
the repository save inserts an record in Adventure first and then inserts
into Booking for that Adventure.
*LOG-*
[EL Fine]: sql: Connection(-49208622)--INSERT INTO ADVENTURE
(ADVENTURE_NAME, DESCRIPTION, ) VALUES (?, ?)
[EL Fine]: sql: Connection(-49208622)-- bind => [test, null]
[EL Fine]: sql: Connection(-49208622)--SELECT CURRENT_TIMESTAMP()
[EL Fine]: sql: Connection(-49208622)--INSERT INTO BOOKING (BOOKING_ID,
ADVENTURE_NAME, CUST_EMAIL) VALUES (?, ?, ?)
[EL Fine]: sql: Connection(-49208622)-- bind => [101, test, null, null]
I have another test that uses the EntityManager got from the repository to
persist and then the repository.flush, and I see the JPA
IllegalStateException buried deep within the DeltaSpike Exception.
*@Test*
public void cannotCreateNewAdventureFromBookingJPA() throws Exception {
Booking booking = new Booking ();
Adventure adventure = new Adventure ("test");
booking.setAdventure(adventure);
EntityManager entityManager =
this.bookingRepository.getEntityManager();
entityManager.getTransaction().begin();
* entityManager.persist(booking);
this.bookingRepository.flush();*
LOG-
org.apache.deltaspike.data.api.QueryInvocationException: Failed calling
Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
calling Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
calling Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
java.lang.reflect.InvocationTargetException,message=null
at
org.apache.deltaspike.data.impl.handler.QueryHandler.invoke(QueryHandler.java:91)
at
org.apache.deltaspike.proxy.impl.invocation.DelegateManualInvocationHandler.proceedOriginal(DelegateManualInvocationHandler.java:46)
at
org.apache.deltaspike.proxy.impl.invocation.AbstractManualInvocationHandler.invoke(AbstractManualInvocationHandler.java:63)
at
org.apache.deltaspike.proxy.impl.invocation.DelegateManualInvocationHandler.staticInvoke(DelegateManualInvocationHandler.java:39)
at
com.myApp.repository.BookingRepository$$DSPartialBeanProxy.flush(Unknown
Source)
at
com.myApp.domain.booking.jpa.BookingJpaRelationshipAnnotationsIntTest.cannotCreateNewAdventureFromBookingJPA(BookingJpaRelationshipAnnotationsIntTest.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:340)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:312)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:174)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:366)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:392)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:141)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed
calling Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
org.apache.deltaspike.data.api.QueryInvocationException,message=Failed
calling Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
java.lang.reflect.InvocationTargetException,message=null
at
org.apache.deltaspike.data.impl.builder.DelegateQueryBuilder.execute(DelegateQueryBuilder.java:66)
at
org.apache.deltaspike.data.impl.builder.QueryBuilder.executeQuery(QueryBuilder.java:63)
at
org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner$1.proceed(TransactionalQueryRunner.java:77)
at
org.apache.deltaspike.jpa.impl.transaction.ResourceLocalTransactionStrategy.execute(ResourceLocalTransactionStrategy.java:133)
at
org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner.executeTransactional(TransactionalQueryRunner.java:72)
at
org.apache.deltaspike.data.impl.tx.TransactionalQueryRunner.executeQuery(TransactionalQueryRunner.java:54)
at
org.apache.deltaspike.data.impl.handler.QueryHandler.invoke(QueryHandler.java:79)
... 39 more
Caused by: org.apache.deltaspike.data.api.QueryInvocationException: Failed
calling Repository:
[Repository=com.myApp.repository.BookingRepository,entity=com.myApp.domain.booking.Booking,method=flush,exception=class
java.lang.reflect.InvocationTargetException,message=null
at
org.apache.deltaspike.data.impl.builder.DelegateQueryBuilder.invoke(DelegateQueryBuilder.java:105)
at
org.apache.deltaspike.data.impl.builder.DelegateQueryBuilder.execute(DelegateQueryBuilder.java:57)
... 45 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.apache.deltaspike.data.impl.builder.DelegateQueryBuilder.invoke(DelegateQueryBuilder.java:117)
at
org.apache.deltaspike.data.impl.builder.DelegateQueryBuilder.invoke(DelegateQueryBuilder.java:97)
... 46 more
*Caused by: java.lang.IllegalStateException: During synchronization a new
object was found through a relationship that was not marked cascade PERSIST:
Adventure{name=test}.*
at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:303)
at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:706)
at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:431)
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:798)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40)
at
org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
at
org.jboss.weld.proxies.EntityManager$1729017240$Proxy$_$$_WeldClientProxy.flush(Unknown
Source)
at
org.apache.deltaspike.data.impl.handler.EntityRepositoryHandler.flush(EntityRepositoryHandler.java:201)
... 52 more
*If the second test is changed to use Entity Manager for flush too then I
get the expected error*
LOG –
*java.lang.IllegalStateException: During synchronization a new object was
found through a relationship that was not marked cascade PERSIST:
Adventure{name=test}.*
at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:303)
at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:706)
at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:431)
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:798)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40)
at
org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
at
org.jboss.weld.proxies.EntityManager$1729017240$Proxy$_$$_WeldClientProxy.flush(Unknown
Source)
at
com.myApp..booking.jpa.BookingDeJpaRelationshipAnnotationsIntTest.cannotCreateNewAdventureFromBookingJPA(BookingDeJpaRelationshipAnnotationsIntTest.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:340)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:312)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:174)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:366)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:392)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:141)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
--
View this message in context:
http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/Cascade-persist-and-merge-with-Repository-tp4661002.html
Sent from the Apache DeltaSpike Incubator Discussions mailing list archive at
Nabble.com.