play-ebean
play-ebean copied to clipboard
Persistence hooks not working in v6.2.0-RC7
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
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...
Hmm... Maybe @rbygrave can help to find where to dig?
@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 ah, we're only specifying a play-ebean version, so whatever version the plugin brings in.
Any chance this change could be related? Just a guess since it's related to annotation processing.
@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
Hmm... Ebean was updated from 12.8.1 to 12.16.1, maybe problem is here?
@rbygrave could javax.persistence.PreUpdate
be broken between 12.8.1 and 12.16.1?
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:
- try against Ebean version 13.6.4
- 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);
}
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).
@bion see how to update Ebean here: https://github.com/playframework/play-ebean/issues/290#issuecomment-1126729369
Thank you for the responses! I tried
- setting the property to dirty manually, as in the code example
- setting the EBean version to 13.6.4 using dependencyOverrides in both plugins.sbt and build.sbt
- 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.