https://github.com/akuniutka/hibernate-base-entity
A base class for Hibernate-managed JPA entities with proper implementations of equals() and hashCode()
https://github.com/akuniutka/hibernate-base-entity
hibernate java jpa spring spring-boot
Last synced: 30 days ago
JSON representation
A base class for Hibernate-managed JPA entities with proper implementations of equals() and hashCode()
- Host: GitHub
- URL: https://github.com/akuniutka/hibernate-base-entity
- Owner: akuniutka
- License: apache-2.0
- Created: 2025-04-18T07:36:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-29T15:43:24.000Z (about 1 year ago)
- Last Synced: 2025-04-29T16:44:22.054Z (about 1 year ago)
- Topics: hibernate, java, jpa, spring, spring-boot
- Language: Java
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hibernate Base Entity
A base class for Hibernate-managed JPA entities with proper
implementations of `equals()` and `hashCode()`. Inspired by
[Andrey Oganesyan](https://github.com/andreyoganesyan)'s,
[Georgii Vlasov](https://github.com/honest-niceman)'s,
[Thorben Janssen](https://github.com/thjanssen)'s posts
([1](https://habr.com/ru/companies/haulmont/articles/564682/),
[2](https://tinyurl.com/4uaecbzy), [3](https://tinyurl.com/mx4msnvu))
on side effects that Lombok's
`@EqualsAndHashCode` annotation brings in when applied to such
entities:
- HashSet and HashMap incorrectly work with the entities,
- Hibernate may load data for lazy fields where not intended.
The new superclass solves both of these problems.
# How to use
1. Copy the class to your project.
2. Inherit JPA entities from the class.
3. Ensure that the primary key in related tables has name `id` and
type `UUID`.