Reputation: 7072
I have a class which I don't want it to be stored on the database, basically it is used for receiving such info from a http request.
class Address {
private String address;
private String postCode;
// + getters and setters
}
Bear in mind that this class is not an entity. Now I'd like to create an entity by inheriting from it.
@Entity
class StorableAddress extends Address {
// id and a few more fields.
}
When I save a StorableAddress it doesn't save any field from Address (address and postCode). Is there a solution for that or do I have to copy all the fields?
Upvotes: 0
Views: 61
Reputation: 2449
Short answer - you should copy values and not use inheritance.
What you are describing is a DTO pattern.
In order to avoid boilerplate code when working with DTOs, you can use tools like MapStruct
Upvotes: 1