[
https://issues.apache.org/jira/browse/OPENJPA-1677?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Vermeulen updated OPENJPA-1677:
-------------------------------
Attachment: openjpa-1677_sscce.zip
This sscce contains two entities and a JUnit 4 test which shows the problem.
It can be built with Maven or perhaps you can manually add openjpa, junit and
hsqldb to the classpath to run it.
The succeedingExample now runs after the failingExample which gives the
reentrant exception.
As I said, the weird thing is that when putting the failingExample after the
succeedingExample the reentrant exception does not occur.
> "InvalidStateException: Detected reentrant flush..." while building an error
> message for an earlier exception
> -------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-1677
> URL: https://issues.apache.org/jira/browse/OPENJPA-1677
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 2.0.0
> Reporter: Vermeulen
> Attachments: openjpa-1677_sscce.zip
>
>
> This error seems to only seems turn up when several criteria are met...
> I am calling entityManager.merge for a new entity that has a required
> ManyToOne field set to null. This naturally gives an error like
> "org.apache.openjpa.persistence.InvalidStateException: The field "test" of
> instance "TestEntity " contained a null value; the metadata for this field
> specifies that nulls are illegal."
> But under certain circumstances, while building the error message of this
> error a new error occurs which masks the original error message. This message
> is extremely confusing to me.
> When OpenJPA builds the error message for the original InvalidStateException
> it seems to call the toString() method of my entity, which in it's turn gives
> the "Detected reentrant flush" when:
> 1) inside the toString() method of my entity I acces the id field
> 2) the id field is annotated with @GeneratedValue(strategy =
> GenerationType.IDENTITY)
> The stack trace I get is:
> Exception in thread "main" <openjpa-2.0.0-r422266:935683 fatal user error>
> org.apache.openjpa.persistence.InvalidStateException: Detected reentrant
> flush. Make sure your flush-time instance callback methods or event
> listeners do not invoke any operations that require the in-progress flush to
> complete.
> at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2033)
> at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1808)
> at
> org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:609)
> at
> org.apache.openjpa.kernel.StateManagerImpl.assignField(StateManagerImpl.java:696)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(StateManagerImpl.java:1608)
> at
> org.apache.openjpa.kernel.StateManagerImpl.accessingField(StateManagerImpl.java:1591)
> at entities.TestEntity.pcGetid(TestEntity.java)
> at entities.TestEntity.toString(TestEntity.java:34)
> at java.text.MessageFormat.subformat(MessageFormat.java:1246)
> at java.text.MessageFormat.format(MessageFormat.java:836)
> at java.text.Format.format(Format.java:140)
> at java.text.MessageFormat.format(MessageFormat.java:812)
> at
> org.apache.openjpa.lib.util.Localizer$Message.getMessage(Localizer.java:277)
> at
> org.apache.openjpa.util.OpenJPAException.<init>(OpenJPAException.java:64)
> at org.apache.openjpa.util.UserException.<init>(UserException.java:47)
> at
> org.apache.openjpa.util.InvalidStateException.<init>(InvalidStateException.java:34)
> at
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:553)
> at
> org.apache.openjpa.kernel.SingleFieldManager.preFlush(SingleFieldManager.java:491)
> at
> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2957)
> at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
> at
> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1047)
> at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2077)
> at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037)
> at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955)
> at
> org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
> at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1479)
> at
> org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925)
> at
> org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:559)
> at MinimalExample.saveInTransaction(MinimalExample.java:41)
> at MinimalExample.failingExample(MinimalExample.java:29)
> at MinimalExample.main(MinimalExample.java:15)
> Why is OpenJPA calling the toString() method anyway, this seems to be
> dangerous...
> This second error goes away and I get the original error when I either remove
> the access tot the id field inside my toString() method or when I simply use
> @GeneratedValue with the default strategy.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.