PersistenceException: Failed to locate field


Hi, have recently been running into this issue when changing the schema:

com.objectdb.o._PersistenceException: Failed to locate field

in this case, adding a primitive String field to an Entity.

pretty sure that in the past schema evolution would not have triggered errors, is this case, a simple new field, shouldn't the policy be to add a null in that field, or other default for that primitive.

Specifically, from:

"Fields in the new schema that do not have matching fields in the old schema are initialized with default values (0, false or null)."

is this a bug, or have I somehow configured the database to complain about this?



The schema evolution should work in this case, nothing was changed.

An exception may be thrown if you mix old and new enhancement. Please make sure that after the change you only use a clean build of your application with fresh enhancement.

ObjectDB Support

Thanks, though I've been using this enhancement for ages (I think it's actually means no enhancement, serialization only):


    <enhancement agent = "false" reflection = "warning"/>

    <cache ref = "weak" level2 = "20m"/>

    <fetch hollow = "true"/>

    <persist serialization = "true"/>

    <cascade-persist always = "true" on-persist = "true" on-commit = "true"/>

    <dirty-tracking arrays = "true"/>


Changed settings to default:

    <enhancement agent = "true" reflection = "warning"/>
    <cache ref = "weak" level2 = "20m"/>
    <fetch hollow = "true"/>
    <persist serialization = "false"/>
    <cascade-persist always = "true" on-persist = "true" on-commit = "true"/>
    <dirty-tracking arrays = "true"/>

and still get this error, so that's not the problem.

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: com.objectdb.o._PersistenceException: Failed to locate field field app.model.Auction.name2 using reflection
at com.objectdb.o._PersistenceException.b(
at com.objectdb.o.JPE.g(
at com.objectdb.o.ERR.f(
at com.objectdb.o.OST.onObjectDBError(
at com.objectdb.jpa.EMF.createEntityManager(
at javax.persistence.EntityManagerFactory$createEntityManager$ Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
at app.database.ObjectDbDatabase.<init>(ObjectDbDatabase.groovy:61)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.codehaus.groovy.reflection.CachedConstructor.invoke(
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(
at AuServerRedis.<clinit>(AuServerRedis.groovy:79)
Caused by: com.objectdb.o.UserException: Failed to locate field field app.model.Auction.name2 using reflection
at com.objectdb.o.MSG.d(
at com.objectdb.o.UMR.P(
at com.objectdb.o.UMR$T.i(
at com.objectdb.o.MMM.<init>(
at com.objectdb.o.UTY.W(
at com.objectdb.o.UTY.S(
at com.objectdb.o.TYS.l(
at com.objectdb.o.MST.UP(
at com.objectdb.o.WRA.UP(
at com.objectdb.o.STC.m(
at com.objectdb.o.SHN.K(
Caused by: java.lang.NoSuchFieldException: name2
at java.lang.Class.getDeclaredField(
at com.objectdb.o.UMR$T.i(
... 12 more

The stack trace is thrown on the server side. Maybe the server has access to an old version of the class (in its classpath) without the new field.

ObjectDB Support

I'm wondering if any of the classes are actually being enhanced.

I'm not using command line enhancement, nor programmatic enhancement, just relying on the config setting:

<enhancement agent = "true" reflection = "warning"/>

Am wondering if there is a way to know what settings ODB is using when it starts up?

Would be useful to log the location of the config file it is using, plus the contents of that config file, given that I've found many cases where the config file it's actually using isn't as expected, eg. in production vs development.

So, would be useful to log, at startup, current config file location and contents.

So, back to this question: does schema evolution work where you're relying only on the enhancement setting in the config file?


You may not be using enhancement. But schema evolution should still work.

ObjectDB Support

ok, so problem resolves if I add programmatic enhancement:

static void main ( args ) {


Note: I removed programmatic many years ago because of some issue which I believe may have been related to my use of groovy instead of java. But, now it seems to be working fine.

I would still consider it a bug that enhancement based only on the XML agent=true flag, and no command line or programmatic enhancement, complains about schema evolution.

Or, at least there should be a note that enhancement based only on the XML setting won't allow schema evolution.


not sure how to debug your question re the server having access to an old version,

shouldn't it automatically flush it's caches if the schema evolves?

or at least shouldn't that be a user setting?

Anyway the problem goes away with programmatic enhancement, which if I recall from the past, adds setters and getters and is much faster, or has that changed?



There is a warning in the documentation (at the end of the Enhancer page) against the configuration based enhancement, which in some environments doesn't work (it is not something in the control of ObjectDB). Note that your current enhancement call is also not perfect, as it may fail if class for enhancement is loaded by the JVM before enhancement, but as long as it works it is fine.

Reflection should still work, including in schema evolution, and the cause for this failure is still unclear. But enhancement is certainly recommended in production as it produces faster code.

ObjectDB Support
Thanks, I did notice that I needed to run the program twice to get enhancement to work. There is a block static { .... } So perhaps I should out the enhancement code in there first or have a proxy class which calls the main class, if I recall that was the recommended solution But having to run it twice is fine for me.