Skip to content
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

M2M property is empty in preDelete of BeanPersistAdapter #3529

Open
Wosch96 opened this issue Dec 16, 2024 · 0 comments
Open

M2M property is empty in preDelete of BeanPersistAdapter #3529

Wosch96 opened this issue Dec 16, 2024 · 0 comments

Comments

@Wosch96
Copy link

Wosch96 commented Dec 16, 2024

We have a BeanPersistAdapter with a preDelete method. The BeanPersistAdapter is registered for class "A", which has a M2M relation to class "B" with CascadeType.REMOVE. Now "A" references four objects of "B".

Expected behavior

The preDelete() method of the "A"BeanPersistAdapter should contain a list with four objects of "B".

Actual behavior

The List is empty.

Steps to reproduce

I also tested this with the ebean test models (MnyB and MnyC):

  1. Create a MnyBPersistAdapter.
public class MnyBBeanPersistAdapter extends BeanPersistAdapter {
  @Override
  public boolean isRegisterFor(Class<?> cls) {
    return MnyB.class.isAssignableFrom(cls);
  }

  @Override
  public boolean preDelete(BeanPersistRequest<?> request) {
    if (((MnyB) request.bean()).getCs().isEmpty()) {
      System.out.println("MnyB contains zero elements of MnyC.");
    } else {
      System.out.println("MnyB contains elements of MnyC.");
    }
    return true;
  }
}

Create a MnyB object and add a MnyC object to the M2M reference.

  @Test
  public void test() {
    MnyB mnyB = new MnyB();
    MnyC mnyC = new MnyC();
    mnyB.getCs().add(mnyC);
    DB.save(mnyC);
    DB.save(mnyB);

   MnyB mnyBFromDB = DB.find(MnyB.class, mnyB.getId());
    // The preDelete of the BeanPersistAdapter should contain one object of MnyC.
    assertThat(mnyBFromDB).extracting("cs").isEqualTo(List.of(mnyC));

    DB.delete(mnyBFromDB);
  }

The test runs green and the console shows the following output:

 MnyB contains zero elements of MnyC.

Tell me if I'm wrong, but I think that the list of MnyC reference objects should not already be emptied in the PreDelete().
I am looking forward to your opinion.

Thanks,
Wosch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant