Quick Fix: Weblogic 10.3.x – How To Solve “org.apache.openjpa.
persistence.
InvalidStateException: Detected reentrant flush…”

I was performing a Java EE App migration to Weblogic 10.3.6, that worked very well in other Java EE Application Servers. The Java EE App runs on MySQL DB. Unfortunately, there was this annoying little problem that caused the whole application to fail. Everytime when I deploy the EAR, it gives an exception stack like the below:

...
Exception in thread "main"  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)
...
Note:It doesn't happen on Weblogic 12c. Only Weblogic 10.3.x is affected.

Well, you get the idea…

While searching on Google, I’ve found a bug report on OpenJPA: link, which indeed it has yet to be fixed at the time of this writing.

If that’s the problem, how did I fixed it?

Solution:

As I checked on the entity classes and discovered that the primary key/ID field was furnished with the annotation like the below:

If you have an entity annotations like these, the problem actually lies on the “@Basic( optional = false )“. All you need to do is to remove that and have something very simple like this:

@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "PK" )
private Long pk;

You are good to go. Problem solved. Hopefully, this piece of info could help someone out there to avoid such a pitfall.

Born and currently resides in Malaysia, a seasoned Java developer whom had held positions as Senior Developer, Consultant and Technical Architect in various enterprise software development companies.