Re: Custom keys and models with objectIdClass, cause an exception when quering using mongo

Manuel Castillo <contact@...>

Hi Andy,

Thanks for the response! I didn't change the queries since we need pretty much our current key configuration; but you gave me an idea: instead of direclty passing the Key object to getObjectById; we changed this to building a String with the sintax: Key.class.getName() +":" +key.toString() so we delegate the key construction to an ObjectId inside the fetchObject method. This is working great! No other changes were required.


2018-04-17 2:40 GMT-05:00 Andy <andy@...>:

I can run an abstract base class + concrete subclass with a basic own definition of PK, and then persist an object (of the concrete type), and then call getObjectById using that PK (with it doing a database call). It works (with MongoDB, and also with RDBMS, and likely any other datastores).

Consequently you should look at your code, and run the same thing but without your PK class (i.e using the built-in PK classes) and see what happens.
Then just create a very simple own definition of PK class (as the `objectIdClass`) ... as per the example in the docs ... and see if that works. If it does work then your PK class is the problem.

A "second class type" is defined in the docs and the JDO spec.

It is fairly safe to conclude that if something works with RDBMS then you should NOT be considering changing ANY code in `datanucleus-core` just to get some minority case on MongoDB to work (if that indeed ends up as the conclusion).

Join to automatically receive all group messages.