문제

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