Replies: 1 comment 5 replies
-
Firstly, I believe this use case of "query where lazy loading is disabled" ... is actually better served by "query returning fully immutable read only entities" That is, instead I want to execute a query that returns entities that:
So this is actually the feature that I'm working on but haven't released yet etc. With this feature in mind we come back to the original question ...
Today to me this feels like it was a mistake, and I've had a couple of conversations with people that suggests it was a mistake. The plan is to support queries that return fully immutable objects / object graphs. When we do that, and people can use that feature then I think it might be clearer that the "mutable beans but with lazy loading disabled" option is something people will not actually use in practice, that they will prefer the fully immutable query instead. |
Beta Was this translation helpful? Give feedback.
-
Some people might prefer a kind of LazyInitialisationException be thrown, instead of getting "null" for non-loaded lazy fields when lazy loading is disabled (especially project wide). That seems useful, because it allows more straightforward catching of cases where developers access non-loaded field by mistake. Yet, LazyInitialisationException has its own cons.
Could Ebean optionally have a project wide setting to enable throwing a kind of LazyInitialisationException instead of getting "null" for non-loaded lazy fields?
From here (https://ebean.io/architecture/compare-hibernate) it seems that the main idea behind absence of LazyInitialisationException in Ebean is because Ebean doesn't see harm in loading fields in another transaction under the default read committed isolation level. That makes sense. However lazy loading is often seen as an anti pattern and is avoided completely, so "null"s would just be returned instead, which has its own cons, as described above. Could Ebean maintainers share reasoning on why it was chosen to return null instead of an exception, when lazy loading is disabled?
Beta Was this translation helpful? Give feedback.
All reactions