-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Hibernate proxies cause problems with equals method's direct property access. #183
Comments
👤 silvaran 🕗 Mar 22, 2010 at 18:19 UTC What steps will reproduce the problem?
What is the expected output? What do you see instead? What version of the product are you using? On what operating system? Please provide any additional information below. boolean useAccessors() = false; If true, Lombok would use generated (if applicable) or user-specified |
👤 silvaran 🕗 Mar 22, 2010 at 18:19 UTC |
👤 silvaran 🕗 Mar 22, 2010 at 18:19 UTC |
👤 silvaran 🕗 Mar 22, 2010 at 18:20 UTC Forgot to put "useAccessors=true" in the @ EqualsAndHashCode annotation, but you get |
👤 reinierz 🕗 Mar 22, 2010 at 19:41 UTC Actually, equality (and thus, hashCodes) for JPA/Hibernate proxies is a hairy issue. For example, hitting each field We've met this need by allowing you write @ EqualsAndHashCode(of="foo"), where foo should be some simple |
👤 silvaran 🕗 Mar 22, 2010 at 20:05 UTC The example I posted actually satisfies the criteria you specified (write The hashCode portion of the annotation doesn't suffer from the uninitialized proxy Now my opinion is if I'm taking time enough to use "of={ ... }", then Even without Hibernate, can I make a valid case for a property that needs to be Note there's no "myProp" property, but it looks like there is to other callers since |
👤 silvaran 🕗 Mar 22, 2010 at 20:05 UTC |
👤 reinierz 🕗 Mar 23, 2010 at 06:46 UTC Hibernate POJOs are always annotated with @ Entity, no? It would be a rather sizable injection of 'magic', but how about this: We'll switch to calling the get methods if there's an @ Entity annotation? The alternative is that we simply always use getX() instead of X; the performance impact is negligible as the |
👤 silvaran 🕗 Mar 23, 2010 at 16:54 UTC I like your note about the performance impact. I think you'd have a better @ Entity is only used when annotations are used to map Hibernate POJOs. XML mapping Or we could rally Orasun to add true property support a la C﹟. :) |
👤 reinierz 🕗 Mar 24, 2010 at 23:14 UTC Oh, yeah, Orasun is going to get right on that lickety split :) So, the concensus is for Roel and I to sit down and figure out if there's any big (negative) impact to rerouting the Can anyone help us along and point out some issues with going the getter route? Any performance issues |
👤 mwanji 🕗 Mar 25, 2010 at 15:36 UTC In a hand-written equals(), I use getters, too, which seems to be the recommended way And you'd have to exclude getId() to be able to compare a saved object to an unsaved |
👤 silvaran 🕗 Mar 25, 2010 at 15:51 UTC I use getters as well, but usually only for the argument (e.g. 'return In any case, I make sure the object graph traversed by the equals() method only goes |
👤 mwanji 🕗 Mar 25, 2010 at 16:04 UTC "I use getters as well, but usually only for the argument" I guess that works because the proxies implement an equals() that delegates to the "this.getParent().getOtherParent().getAnotherParent().getName()" Does that really happen? I was thinking more along the lines of |
👤 silvaran 🕗 Mar 25, 2010 at 16:26 UTC
That was just an example. In reality it would be exactly like your example equals( Object o ) { So each of those two calls to equals() would cause two separate database hits (4 That's why I'm a little confused about this stuff, especially as to how responsible |
👤 silvaran 🕗 Mar 25, 2010 at 16:28 UTC This issue report is turning into a Hibernate issue report, but I just wanted to add |
👤 silvaran 🕗 Apr 01, 2010 at 20:40 UTC Proxies don't initialize the primary key either. Unless lombok's equals() |
👤 reinierz 🕗 Jul 19, 2010 at 15:09 UTC Sounds like just using the getters (if available) is the right option. |
👤 reinierz 🕗 Jul 22, 2010 at 12:21 UTC Completed in time for release 0.9.3 (Burrowing Whale) in a series of commits, ending in ceda2e5 |
End of migration |
Should help for issues: projectlombok#105, projectlombok#168, projectlombok#142, projectlombok#183 improved inspections for invalid val definitions
Migrated from Google Code (issue 110)
The text was updated successfully, but these errors were encountered: