I believe I'm seeing lots of unexpected queries from my morphia process over to my mongodb for lazy objects. Please confirm or correct my understanding and advise if there is a way to avoid these queries.
Here's the setup:
class Foo has an embedded list of class Bar objects. Class Bar has a lazy=true reference to class Baz.
@Entity("foo")
Class Foo {
@Embedded
private List<Bar> bars = Lists.newArrayList();
Class Bar:
@Reference(lazy=true) Baz baz;
When an instance of foo is loaded, the list of Bar instances is created (I can see a @PreLoad method call happening). It looks like the creation of the lazy reference proxy for baz is verifying that the id of the lazy object is a valid id by sending a query to mongo. I can see these queries appear in the db.system.profile.find output.
The problem I'm running into is that even with a short list fo Bar instances, each instance is causing a unique, independent query to mongo. Worse yet, in my actual class I have other lazy references as well to other classes (collections) and they two are getting validated by individual queries.
As you might guess, the number of round trips to the mongo server is starting to have in impact on the performance.
The odd thing is that I don't see similar queries for direct lazy references. I.e. Foo also has @Reference(lazy=true) List<BlargleBean> blargles. That is, I only see these unexpected queries for lazy references in instances that are embedded.
Questions:
1. is my understanding correct that morphia makes a query to mongo to confirm that the id from a reference is good before creating the lazy proxy instance?
2. If so, is there any way to avoid this?
At this point I'm looking to refactor my data model to stop using references altogether and store only the ObjectIds and manage loading them as my app needs.
Thanks
greg