E
E
Eugenue Cesarevich2021-03-21 17:40:39
Java
Eugenue Cesarevich, 2021-03-21 17:40:39

Persistable or AbstractPersistable?

Previously, entities inherited from Persistable., I also had to hashCode()do equals()it. Now I saw the AbstractPersistable class, and everything is already there. Is there any point in using Persistable if there is an AbstractPersistable? If it makes sense, then in what situations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-03-21
@cot_shaurma

Interface Persistable<ID>
Persistable is an interface.
Class AbstractPersistable<PK extends Serializable>
AbstractPersistable is an abstract class that implements the Persistable interface. Due to the fact that this is a class, the equals() & hashcode() methods are already implemented in it.
As to what to use, here is an excerpt from the Spring documentation:


AbstractPersistable is a one-stop shop for very basic use cases. The only thing it actually does is setting up default id generation. If you want to customize that, there's nothing you gain from extending the class. So we generally recommend to neither extend the class nor implement Persistable unless you really need to customize when Spring Data shall consider the entity new.

https://docs.spring.io/spring-data/data-jpa/docs/c...
https://docs.spring.io/spring-data/commons/docs/cu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question