Issue #473: Unexpected Exception during commit

Type: Bug ReoprtPriority: NormalStatus: FixedReplies: 5

I'm testing code that otherwise has been working with a clean database. I have seen several examples of the following exception. It never seems to happen in the same place twice, though.

If you can give me a hint as to what would internally cause this, I'll try to reproduce it.



[ObjectDB 2.2.9_01] javax.persistence.RollbackException
Failed to commit transaction: Unexpected internal exception (error 613)
        at com.objectdb.jpa.EMImpl.commit(
        at com.fastmodel.fastplan.db.EntityManagerFactory.doFilter(
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(
        at org.apache.catalina.core.StandardWrapperValve.invoke(
        at org.apache.catalina.core.StandardContextValve.invoke(
        at org.apache.catalina.core.StandardHostValve.invoke(
        at org.apache.catalina.valves.ErrorReportValve.invoke(
        at org.apache.catalina.core.StandardEngineValve.invoke(
        at org.apache.catalina.connector.CoyoteAdapter.service(
        at org.apache.coyote.http11.Http11Processor.process(
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
        at org.apache.tomcat.util.threads.ThreadPool$
Caused by: com.objectdb.o.InternalException: Unexpected internal exception
        at com.objectdb.o.JPE.h(
        at com.objectdb.o.ERR.f(
        at com.objectdb.o.IVP.g(
        at com.objectdb.o.IVP.f(
        at com.objectdb.o.ISP.size(
        at com.objectdb.o.CLT.visitRefs(
        at com.objectdb.o.TVS.j(
        at com.objectdb.o.TVS.cascade(
        at com.objectdb.o.STA.Q(
        at com.objectdb.o.STM.D(
        at com.objectdb.o.OBM.bH(
        at com.objectdb.jdo.PMImpl.bH(
        at com.objectdb.o.OBM.bG(
        at com.objectdb.o.OBM.bE(
        at com.objectdb.jpa.EMImpl.commit(
        ... 15 more
Caused by: java.lang.NullPointerException
        at com.objectdb.o.UMR.u(
        at com.objectdb.o.ENT.loadInverse(
        at com.objectdb.o.IVP.g(
        ... 27 more



According to the stack trace, during commit an attempt to cascade persist through an inverse (mapped by) collection field fails.

I am not sure which reference causes the NullPointerException.

The only reference in that line can never be null as far as I can tell - unless the EntityManager is in a special state that I miss.

On the next line other references that are related to the inverse field are used. Maybe that inverse reference field has special type or setting causing this problem.


ObjectDB Support

I've found a very simple reproducible case that produces the exception every time:

    javax.persistence.EntityManagerFactory emf =

    EntityManager em = emf.createEntityManager();

    em.find(Account.class, 1);



I also tried upgrading to 2.2.9_05. Now when I try to enhance I get:

        at com.objectdb.o.CFG.t(
        at com.objectdb.o.CFG.r(
        at com.objectdb.o.CFG.q(
        at com.objectdb.o.JEN.<init>(
        at com.objectdb.Enhancer.enhance(
        at com.objectdb.Enhancer.enhance(
        at com.fastmodel.fastplan.db.EntityManagerFactory.contextInitialized(
        at org.apache.catalina.core.StandardContext.listenerStart(
        at org.apache.catalina.core.StandardContext.start(
        at org.apache.catalina.core.ContainerBase.start(
        at org.apache.catalina.core.StandardHost.start(
        at org.apache.catalina.core.ContainerBase.start(
        at org.apache.catalina.core.StandardEngine.start(
        at org.apache.catalina.core.StandardService.start(
        at org.apache.catalina.core.StandardServer.start(
        at org.apache.catalina.startup.Catalina.start(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.apache.catalina.startup.Bootstrap.start(
        at org.apache.catalina.startup.Bootstrap.main(

I also get the following on the server:

        at com.objectdb.o.CFG.t(
        at com.objectdb.o.CFG.r(
        at com.objectdb.o.CFG.q(
        at com.objectdb.Server.main(
        at com.objectdb.o.CFG.t(
        at com.objectdb.o.CFG.r(
        at com.objectdb.o.CFG.q(
        at com.objectdb.Server.handleException(
        at com.objectdb.Server.main(
Exception in thread "main" java.lang.NullPointerException
        at com.objectdb.o.CFG.t(
        at com.objectdb.o.CFG.r(
        at com.objectdb.o.CFG.q(
        at com.objectdb.Server.handleException(
        at com.objectdb.Server.main(

I am wondering if this is related or if it is a different issue.

I will email you the src and odb file.




The new (enhancer) exception in build 2.2.5_05 is caused by using the new build with an older configuration file.

The old (commit) exception is the result of defining an invalid mapped by field.

Build 2.2.5_06 fixes both issues and produces the following error message for your test:

Caused by: com.objectdb.error.UserException: account is not found in type Player (mapped by field com.fastmodel.fastplan.entities.Account.players)
at com.objectdb.error.ErrorMessage.construct(
at com.objectdb.type.user.UserMember.runInverseQuery(
at com.objectdb.pc.track.EntityTracker.loadInverse(
at com.objectdb.type.inv.InverseProxy.loadCollection(
... 22 more

The owner side, account, is currently defined in Person, but not in Player (and other classes).

Please notice that ObjectDB can manage collections directly with no mappedBy - and it is also much more efficient. Therefore, consider removing the mappedBy definition instead of defining the owner account field.

ObjectDB Support

Many thanks for the advice and improved error messages!

A few questions about mapped collections - I do use direct collections when it makes sense from an OO perspective. I thought, however, that direct collections require loading the entire collection in order to access or alter even a single item. Is that true? In cases where I have a large number of entities that are not used as a collection, I assumed a mappedBy relationship would be better. Most often I refer to these objects directly, not as a collection. But if I need to iterate through all of them, the mapping is there for convenience.

The other thing I like about mappedBy is it gives me bi-directional navigation of my entities, even though I am only managing a reference on one side. If I used a direct collection, I would have to manage both sides. Is there a way to have bi-directional one-to-many mappings with a direct collection?



You are right - mappedBy collections have the following advantages:

  • Small changes to very large collections may be faster.
  • Only with mappedBy you get bi-directional relationship managed automatically.

Thank you for this report.

ObjectDB Support