Comments (7)
๐ค lhoriman ย ๐ Aug 18, 2009 at 01:34 UTC
For JPA domain objects (classes annotated with @ Entity), equality is best defined as:
- Are the classes equal
- Are the ids equal
The id of a JPA entity will either be:
- A compound of all the fields annotated with @ javax.persistence.Id
or: - The single field annotated with @ javax.persistence.EmbeddedId
Some things to consider:
- @ Id and @ EmbeddedId annotations might come from superclasses.
- It might also be a good idea to have the @ EqualsAndHashCode(include={"xxx"}) option as well
since it's still possible for (masochistic) developers to define the ids and relationships in XML.
And it's a useful construct in general. - You might want this to only apply to @ Entity objects.
from lombok.
๐ค reinierz ย ๐ Aug 18, 2009 at 12:07 UTC
This is going to be rather complicated. Full discussion is here:
http://groups.google.com/group/project-lombok/browse_thread/thread/b0e6a34d1bc72526
from lombok.
๐ค reinierz ย ๐ Sep 01, 2009 at 23:45 UTC
We'll support it via include, as triggering on @ Id/@ EmbeddedId has far too many complications (see previous
link).
from lombok.
๐ค jnorris10 ย ๐ Sep 02, 2009 at 16:02 UTC
Defaulting JPA entities to base their equality on @ Id/@ EmbeddedId does not seem like a good idea. Entities
often have a "natural" identifier which is separate from @ Id. In this case, @ Id is used as a surrogate key (making
it easier to manage ORM mapping and refactor the DB schema later). Another advantage is it lets the natural
constraints be enforced in the domain model independent of the persistence mechanism used. Also, in cases
where @ Id is generated from the DB, it allows objects to have a valid notion of equality before they are persisted.
I agree with reinierz, an explicit include properties mechanism is best here. It's the most clear and simple.
from lombok.
๐ค lhoriman ย ๐ Sep 02, 2009 at 16:07 UTC
I think everyones on the same page - an "include" member of the @ EqualsAndHashCode annotation would be
great.
from lombok.
๐ค reinierz ย ๐ Sep 02, 2009 at 23:47 UTC
addressed in f1124aa which will be rolled out in v0.8.5. The
'includes' parameter is called 'of', so you could do:
@ EqualsAndHashCode(of="id")
@ Entity
public class SomePersistedClass { ... }
We've also added fields that start with $ as default excludes. Lombok's own @ Synchronized can generate
these fields, and I expect other automated tools will as well. $ is understood to mean 'generated', and it
seems safer to exclude them by default.
from lombok.
End of migration
from lombok.
Related Issues (20)
- Jakarta Generated support HOT 3
- Support extension method autocomplete HOT 2
- [FEATURE] Add more flexibility to declare copyable annotations
- sorry it was mistake
- [BUG] Javadoc generation fails because of @Builder
- [BUG] Delombok fails on unnamed patterns in Java 22 HOT 1
- [BUG] UtilityClass nested in an enum does not work after upgrading to Java 21
- [BUG] @Delegate does not respect --source and --target HOT 1
- [BUG] Installer Throws a Bunch of Errors
- [BUG][REG 1.18.32] A required class was missing while executing org.eclipse.tycho:tycho-compiler-plugin:4.0.7:compile: org/eclipse/jdt/internal/compiler/parser/Parser
- [FEATURE] @FieldNameConstants Easier overwrite for generated fields HOT 2
- @FieldDefaults: Keep the global setting experimental, make the annotation permanent.
- [FEATURE] Allow to easily add interfaces to Builders
- [BUG] Support for Eclipse 2024-06 (4.32) HOT 11
- [FEATURE] Super Constructor
- [FEATURE] enhance @FieldNameConstants with specific prefix string HOT 2
- [BUG] SuperBuilder does not compile then binding generics to an array HOT 5
- [BUG] SaSessionForFastjsonCustomized็ฑปไธญ็getModelๆฅ้ HOT 1
- [FEATURE] setX() for mutable state, fluent otherwise HOT 2
- [BUG] Lombok 1.18.34 (Edit updated) not working with eclipse 24-06 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lombok.