play-ebean icon indicating copy to clipboard operation
play-ebean copied to clipboard

Persistence hooks not working in v6.2.0-RC7

Open bion opened this issue 2 years ago • 12 comments

Updating from v6.2.0-RC4 to v6.2.0-RC7 has caused a regression where methods annotated with javax.persistence.PrePersist and javax.persistence.PreUpdate are not longer called before insertion or update.

Example usage: https://github.com/seattle-uat/civiform/blob/main/server/app/models/Applicant.java#L74-L76

bion avatar Jun 07 '22 21:06 bion

Thanks for the report! @PromanSEW what do you think? Can you take a look? BTW: This whole -RC versioning thing is a bit of a mess. I did that because someone else who was taking care of this repo before started with RC1 or 2... Maybe it would make sense to start all over with the versioning here...

mkurz avatar Jun 07 '22 21:06 mkurz

Hmm... Maybe @rbygrave can help to find where to dig?

PromanSEW avatar Jun 08 '22 05:06 PromanSEW

@bion which version of Ebean do you use? I assume that 13.6+ I worked for adaptation for Ebean 13.6+ in RC5-RC7, so enhancing can work Also see #290

PromanSEW avatar Jun 08 '22 05:06 PromanSEW

@PromanSEW ah, we're only specifying a play-ebean version, so whatever version the plugin brings in.

bion avatar Jun 08 '22 06:06 bion

Any chance this change could be related? Just a guess since it's related to annotation processing.

bion avatar Jun 08 '22 06:06 bion

@bion I only checked 13.6.0+, this change was a fix for another change (https://github.com/playframework/play-ebean/commit/692ae03c00485d1098ef570dffe69c73ba273f22) in RC6 Final changes from RC4...RC7: https://github.com/playframework/play-ebean/compare/6.2.0-RC4...6.2.0-RC7

PromanSEW avatar Jun 08 '22 07:06 PromanSEW

Hmm... Ebean was updated from 12.8.1 to 12.16.1, maybe problem is here?

PromanSEW avatar Jun 08 '22 07:06 PromanSEW

@rbygrave could javax.persistence.PreUpdate be broken between 12.8.1 and 12.16.1?

PromanSEW avatar Jun 17 '22 02:06 PromanSEW

Well maybe, in that dirty detection of JSON properties changed in 12.11.1 via: https://github.com/ebean-orm/ebean/pull/2274

We got a bug reported 17 days ago (with a workaround) and fixed 13.6.4 https://github.com/ebean-orm/ebean/issues/2710

And this looks at least similar: https://github.com/seattle-uat/civiform/blob/main/server/app/models/Applicant.java#L81 https://github.com/seattle-uat/civiform/blob/main/server/app/models/Applicant.java#L44 ... as this is also a @DbJson property mutated in a @PreUpdate so pretty likely this is the same issue.

@bion Have you created a failing test case? If so, you can run that failing test with:

  1. try against Ebean version 13.6.4
  2. or try explicitly marking the property as dirty/changed via:
  @PrePersist
  @PreUpdate
  public void synchronizeObject() {
    this.preferredLocale =
        getApplicantData().hasPreferredLocale()
            ? getApplicantData().preferredLocale().toLanguageTag()
            : null;
    this.object = objectAsJsonString();

   // explicitly mark the "object" property as dirty / changed
  EntityBean entityBean = (EntityBean)this; // bean
  EntityBeanIntercept ebi = entityBean._ebean_getIntercept();
  int pos = ebi.findProperty("object");
  ebi.setChanged(pos);

  }

rbygrave avatar Jun 17 '22 03:06 rbygrave

but ...

are not longer called before insertion or update

this was not that case in that the methods were being executed, it's just that the @DbJson properties were not treated as dirty. So in this sense it would be very good @bion if you had a failing test case that we could run (because we have no failing test case where these methods don't run).

rbygrave avatar Jun 17 '22 03:06 rbygrave

@bion see how to update Ebean here: https://github.com/playframework/play-ebean/issues/290#issuecomment-1126729369

PromanSEW avatar Jun 17 '22 04:06 PromanSEW

Thank you for the responses! I tried

  1. setting the property to dirty manually, as in the code example
  2. setting the EBean version to 13.6.4 using dependencyOverrides in both plugins.sbt and build.sbt
  3. both together

None of them resolved the problem, from what I can tell. I am testing solutions by running testOnly repository.UserRepositoryTest. The repository.UserRepositoryTest.updateApplicant test fails.

bion avatar Jun 22 '22 19:06 bion