332 words

pm.newObjectIdInstance returns null

2016-06-08 23:05

I am on an emergency upgrade mission. Our production odb file (version 1.0.4) currently corrupts when written to. Importing to 2.6.8. has seemed to fix the corruption problem. So....I am in the middle of testing a 2.6.8 upgrade from 104se_2522. It was plugged in to the existing legacy code (2005'ish). Trying to modify as little as possible. I am having trouble with the following:(names have been simplified)

public MyClass retrieveMyClass(String oid, boolean makeTransient, MyContext context) throws PersistenceLayerException {
       MyClass myclass = null;
              Object objectid = pm.newObjectIdInstance(AFPhysicalPart.class, oid);
              physpart = (MyClass) pm.getObjectById(objectid, false);
              if(makeTransient) myclass= (MyClass) myclass.clone();
              //if(makeTransient) pm.makeTransient(myclass);
        }catch (JDOException jdoe){
        return myclass;

objectid is coming back as null.  Does this problem seem obvious to you?

(There is a complete re-write in the works but not ready for release)

bmcalist's picture
Joined on 2010-05-20
User Post #2
2016-06-08 23:23

The first thing that PersistenceManager's newObjectIdInstance does is to search for an ID class, and if this fails a null is returned.

You can check that operation directly:

Class c = getObjectIdClass((AFPhysicalPart.class)

does it return null?

But are you sure that newObjectIdInstance returns null? Maybe an exception is thrown? Can you post the stack trace?

Note that ObjectDB 1.x (unlike ObjectDB 2.x) supports only numeric ids so it is unclear how your converted database can have string ids.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,522
2016-06-09 00:24

After further checking of newObjectIdInstance implementation in ObjectDB 2.x it seems that it is limited to classes in which an ID class or a primary key is defined explicitly by the application.

Please try a new build 2.6.8_03 that includes an attempt to fix  this limitation.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,523

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB