-
Notifications
You must be signed in to change notification settings - Fork 75
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
null fields shouldn't be equal, but also shouldn't suppress identical copy #932
Comments
So if I understand correctly, when the object is still "new" (i.e., not yet persisted), the id is null. If you have two such objects, you want equals to return false, but EqualsVerifier enforces that they be true. I think you have a good point there, I'll see if I can make that work. Do you think there's a use case for keeping them equal? If so, I'd have to introduce a new kind of Warning, and I'd prefer not to do that if I have the choice. |
if you don't you'll probably need to release a new major version as it would break backwards compatibility on peoples code in a subjective way. Honestly, there probably is, but I don't know what it is. It's probably that people just don't share my opinion and it's hard for me to say for certain. would you have to introduce a new kind of warning? or could you just introduce an alternate method to |
Also, I'm not certain how this impacts I hate thinking of equality... because there's actually at least 2 different kinds, maybe 3. |
OK, thanks. I'll think about how to approach this then. |
ok, correct behavior id == null should not be considered equal. Java Equality is inappropriate for this case, and other methods should be used. I've been documenting what I think are the various cases over in #935 and considering what Domain Driven Design would say. The reality there is that there may not be a good way to say that 2 identical all the way down, new order line items aren't intentional from a DDD perspective. I think the question for you though remains, what does changing this behavior mean? I new major version? how've you been dealing with this? Also it's probable that we'd need to add some better advice/examples of why. I wonder if it would be appropriate to change (at least at the root) to change from only auto detection to having something like |
Turns out that EqualsVerifier already supports the case where you want And yes, I agree the names are awkward (at best). I wrote this bit many years ago, when I hadn't actually used Hibernate or JPA myself yet. Improving the API is already on my todo list, but it will take a while before I get to it. |
This is one of those, JPA surrogate id's can be great but really suck for equals. Given the following
@Embeddable
superclass.I'm thinking that if
id == null
on both sides the object should not be equal, even if they're identical. To be fair these should actually never have a null id past hibernate load in production code.I don't see a good way to test this, this is how I'm testing right now (just lazy subclasses). Neither supressing IDENTICAL_COPY or
withNonnullFields
reads as appropriate because I don't really want to ignore these fields. Especially not because I was giving myself NPE's for a second (calling the updated getter eek).The text was updated successfully, but these errors were encountered: