Giter Site home page Giter Site logo

Comments (7)

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

๐Ÿ‘ค 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.

lombokissues avatar lombokissues commented on July 17, 2024

End of migration

from lombok.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.