I have a model entity with a list of objects:

@ManyToMany
public List<SomeObject> listOfObjects = new ArrayList<>();

When I have fetched such an entity (e.g. find.byId(id)) are there all the fields completly loaded already or is there a lazy loading? What about this list of objects with a many to many relation?

Or more general, can I configure this in ebeans? What is the default?

有帮助吗?

解决方案

First of all in Ebean you don't have to initialize this relation with empty list. You can write simply:

public List<SomeObject> listOfObjects;

and code will work as before.

And the answer to your question:

Yes, by default many-to-many relation is lazily loaded. So when you call find.byId(id) then simple select will be executed. And when you try to use this collection (for example calling listOfObjects.size()) then additional select will be called.
To see how it works you can turn on SQL logging.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top