The Hibernate documentation makes a distinction between an Entity and a Value Type, not a Value Object.
- Object of Entity Type: has its own database identifier
- An object of type value: belongs to the entity, and its constant state is embedded in the table row of the owner object. Value types do not have identifiers or identifier properties.
As far as I remember, the book uses a sample with address , presented as a single String object and user , which contains the address of String:
Implemented as a value type (usually this means a column in the same table at the database level), if the user is deleted, then his address. An address cannot live without a user and cannot be shared.
Implemented as an entity type (which probably means using a separate table), the addresses will exist on their own without a user, and two users will be able to use the same address.
In your case, the order line is not related to order, its constant state is not built into the order line (it makes no sense), it has its own identification (consisting of orderId and productId), the order line is definitely not a value type, it is an object type.
Actually, as soon as you think about alliances (one-to-one, one-to-many, etc.), you will surely manipulate entities.
source share