-
-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty OneToMany when overflowing LazyLoadBatchSize and mixed queries #3381
Comments
We discovered something ! We noticed that Lazy Loading in Ebean have a default value of '10'. May it be correlated ? We tried to call
The problem seems to be linked to MixedQuery because we can workaround the problem by computing all
Yours faithfully, |
What is MixedQuery? edit: Do you mean transaction.setFlushOnMixed(false) ?
Why is the nested |
You are producing a failing test case right? |
Maybe we are wrong about the term used, it was a reference to the The problem seems to occur when we execute the update at the end of each iteration, and so we have a mixing of
This lock is only a helper on our side to avoir having multiple process executing the method concurrently but the problem still occur even if we remove it.
|
Example minimal - https://github.com/ebean-orm-examples/example-minimal |
Just a note in case I forget to mention it later, that the |
What is the concern with Here is the reproducer : Branch where the Asserts fail on fourth element, considering lazyLoading is set to '3' |
Both of these versions do not have this issue/bug.
This doesn't make sense to me in that for #3320 there was NO CHANGE made to ebean at all. That was more that the application needed to change wrt use of transactions in BeanAdapter. So nothing in 3320 requires an upgrade per se.
Now this issue we are hitting here was actually introduced in versions 14.0.0 / 15.0.0 by #3295 in version . This issue didn't exist prior to that. |
Bug explanationThe current summary of this bug is that #3295 introduced a behaviour where bulk updates clear the persistence context. Now the lazy loading of a BeanCollection works with an assumption that the "parent bean" is in the persistence context (and this assumption is broken with that change for this test case). That is, the bulk update is clearing the persistence context - removing the parent bean BEFORE the lazy loading is invoked ... and that doesn't then work because the parent bean isn't in the persistence context. Now for this case we might see that ... if the code just updated the parent (order) beans that would have worked, or if the code had used a stateless update (new order bean populated and then explicitly updated) that would also have worked. This is because for those updates ebean knows it's only updating the single bean. It is the use of the bulk update + 3295 behaviour to clear the PC + lazy loading collection ... that gives us this bug. First thought ...My first thought is to look at the lazy loading collection assuming the parent is in the persistence context. FYI Stateless updateThe stateless update for this case would be: // create a new order bean for a stateless update
var statelessUpdateOrder = new LOrder();
statelessUpdateOrder.setDirty(null);
statelessUpdateOrder.setTotal(totalComputed);
statelessUpdateOrder.setId(lorder.getId());
// use version for optimistic locking (not using prior dirty value)
statelessUpdateOrder.setVersion(lorder.getVersion());
// perform a stateless update
DB.update(statelessUpdateOrder); update lorder set dirty=?, total=?, version=? where id=? and version=?; -- bind(null,30.000,2,1,1) |
As for the issue 3320 As for the versions
Thinking we were running 13.26.1, we were in fact running on Ebean 15.0.1 due to Play-Ebean dependency. As for your tips about stateless update way of writing. We do not use this here because we are updating a Bean according to the couple "Id value / Dirty value" and we do not care about version that can change (no optimistic lock check). Our generated ORM query is : |
…d mixed queries 14.0.0 via #3295 introduced this bug. #3295 introduced a behaviour where bulk updates clear the persistence context. Now the lazy loading of a BeanCollection works with an assumption that the "parent bean" is in the persistence context (and this assumption is broken with that change for this test case). That is, the bulk update is clearing the persistence context - removing the parent bean BEFORE the lazy loading is invoked ... and that doesn't then work because the parent bean isn't in the persistence context. This fix means that when lazy loading many's, the parent beans are putIfAbsent into the persistence context.
…d mixed queries 14.0.0 via #3295 introduced this bug. #3295 introduced a behaviour where bulk updates clear the persistence context. Now the lazy loading of a BeanCollection works with an assumption that the "parent bean" is in the persistence context (and this assumption is broken with that change for this test case). That is, the bulk update is clearing the persistence context - removing the parent bean BEFORE the lazy loading is invoked ... and that doesn't then work because the parent bean isn't in the persistence context. This fix means that when lazy loading many's, the parent beans are putIfAbsent into the persistence context.
…or IntelliJ plugin to be released Adding this means that it will work with an old ebean-agent. It takes a few days to get a new IntelliJ plugin released and we can't wait due to wanting to release the bug fix for #3381
Fix for #3381 - Empty OneToMany when overflowing LazyLoadBatchSize an…
FYI: The fix for this is available in versions 14.0.2.1, 14.0.2.1-javax as patch to 14.0.2 and in versions 14.1.0, 14.1.0-javax, 15.1.0 (which include other changes that has already been merged into master). |
Context
We never had this problem in 4 years. It start doing this since we upgrade from Ebean 13.22.0 to 13.26.1.
We did this upgrade in order to fix the following issue : #3319
We tried to upgrade to 15.0.2 but the issue still exists.
Expected behavior
The linked entites should be loaded from the database.
Actual behavior
We randomly get an empty array when our process access a oneToMany lazy-loaded attribute.
However, the associated entities are well stored in the database and should be returned.
Note : We did not succeed ot reproduce on local development, but this happens once every two days on our production server.
Steps to reproduce
Order entity :
OrderLine entity :
Business code that produce the problem :
No specific console, everything is running fine, no error, no warn.
Thanks in advance for your help.
Yours faithfully,
LCDP
The text was updated successfully, but these errors were encountered: