What is the difference between entity and value types at the object level. I understand that entity will have an id but value won't but why do we need different ways to map entity vs value types?
Is it done so that hibernate can apply any optimization to value type?
An entity already defines the table where it's persisted. So when you have a list of B entities in an entity A, there is no need to define the target table for the Bs: B already defines it. Value types don't have any associated table, so the mapping of a List<String>
in entity A must define which table will be used to store this list.
Moreover, value types, by definition are always completely owned by their containing entity. Once you delete the entity, you also delete all the Strings associated to this entity. This is not the case with entities: when you delete a Course entity, you don't delete all its students.
These are just two examples showing that different mapping properties must be defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With