-
Notifications
You must be signed in to change notification settings - Fork 76
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
Don't prevent using withOnlyTheseFields (etc) when JPA Id fields are present #934
Comments
It's not so much Java that made things complicated. I mean, it's complicated, but other languages (like C#) have exactly the same complexity, and other languages (like Ruby) just ignore it and sweep it under the rug. It's only when you start using JPA/Hibernate when things get messy. I'm not really sure what you're asking for here.
I have to admit I haven't used |
I think it's really a problem with Entities as it's anything that has a lifecycle that has a single identity but it's state changes over time and it persists beyond the current instance of the application.
It doesn't discuss that, but here's the docs.
hmm... maybe this story could be remediated by mentioning this solution in the current errors? maybe we should discuss how there's also another thought that had too, what about distinguishing aggregates (in a Domain Driven Design Sense), they frequently, these days, have an in memory collection of domain events to be emitted later, usually a kind of record of changes to them. Feels like a candidate. This is a transient field, and it's also not one to be serialized for jackson. Anywhays. So to reiterate, I think to solve this issue you should emit something about |
I opened #935 to discuss null ids, version, and dirty checking. Trying to give a more comprehensive look. |
@Test
void abstractEntityEquality() {
EqualsVerifier.forClass(BarEntity.class)
.withRedefinedSuperclass()
.withPrefabValues(AbstractIdentity.class, BarEntity.Id.create(), BarEntity.Id.create())
.suppress(Warning.SURROGATE_OR_BUSINESS_KEY)
.withOnlyTheseFields("id", "version", "dirty")
.verify();
} |
I'm not sure if it makes sense for EqualsVerifier to look at the Maybe the behaviour should be that if this warning is suppressed, it's allowed but not mandatory to include it in In the mean time, would it be an idea to suppress |
It does, at least that's the conclusion I came to in my experiments in #935 although I think perhaps that ticket is better for the discussion of "what" needs to be in a persisted entity check and why. Then action items (if any) can spawn from it. For this ticket, I'd rather focus on my not being able to get Equalsverifier to do what I say is correct, regardless of what anyone thinks is right. I don't seem to be able to get it to "do what I say".
That's what I tried in the comment above, this literally gives me the same error about supressing Btw, all of this code exists in my public repo @Test
void abstractEntityEquality() {
EqualsVerifier.forClass(BarEntity.class)
.withRedefinedSuperclass()
.withPrefabValues(AbstractIdentity.class, BarEntity.Id.create(), BarEntity.Id.create())
.suppress(Warning.SURROGATE_OR_BUSINESS_KEY)
.withOnlyTheseFields("id", "version", "dirty")
.verify(); |
Ah, I missed that you were using But I agree that in that case, |
I've just released version 3.16, which fixes this. |
I'm having a hate relationship with my own thoughts on JPA right now, but...
but I was trying to also compare with the
@Version
field, and that@Version
is just a field that increments in some way for optimistic locking, can be a number or a timestamp (of some kind)but including this in my contract would allow me to have 2 versions of the same entity in a set. Is that a good idea? I don't actually even know what happens if I try to add a matching equals to a set... is it ignored or overwritten, probably the former.
I feel like I want to compare id, version, and find a way to expose the dirty tracking to equals. On the other hand now I'm just wondering if I'm stupid. Sigh, why's everything got to be so complicated? dear creator of java, equals/hashcode is a terrible idea. Somehow this is all my fault... wasn't this my idea from years ago? :'(
I guess my fuss here is that
withOnlyTheseFields
can't be used if I have something marked with an@Id
, thereby taking control out of my handsThe text was updated successfully, but these errors were encountered: