We have a massive object graph and that works fine due the normal 'lazy load' feature available in our ORM (Datanucleus) which works the same way lazy loading works in most other ORMs (eg Hibernate).
The app only loads objects in the graph as we navigate along relationships in the Java code and this is usually 10-20 objects being 'reached' (and therefore loaded from the DB or L2 cache) and in worse case never more than a couple of thousand objects being 'reached' and therefore loaded.
I am trying to serialize just a subset of the object graph, limited by a small subset of classes but one of those classes has a reference into an owner object and that owner object class is part of a much larger chunk of the object graph that 'reaches' to other classes with literally millions of other instances in the database.
As YAMLBeans serializes it uses reflection to discover every relationship of each object then proceeds to load the related objects, which is a great feature normally, but in this case it ends up attempting to load many millions of objects from the DB into memory via the ORM which obviously doesn't end well ;)
Without making any changes to our model is it possible to instruct YAMLBeans to not proceed along a particular relationship in a given class when serializing?
I was wondering if there is (or could be) a YAMLBeans mechanism where we could specify a class + relationship which YAMLBeans should not navigate past when performing serialization. It would be like "short circuiting" or putting a boundary at a point in the object graph which limits the scope of the YAMLBeans serialization process to avoid the "serializing the entire world" problem.
Aside: Having experienced this 'issue' I did think that possibly, in another scenario, with enough RAM, this could be used as a 'feature' to migrate the entire object graph of an app from a current DB to:
- a different RDBMS engine eg., MySQL -> Postgres
- same RDBMS engine but different schema eg., using same class model but mapping to different table layouts or different table names/column names via changed ORM metadata
- a different type of datastore without changing any Java code eg., migrating from Datanucleus using RDBMS to Datanucleus using a NoSQL datastore like Cassandra
or even from one schema to another radically different schema (avoiding creating tricky SQL scripts).