I have tried omitting the @Embedded
annotation and still the fields have been embedded in the table. I cannot find anything which would say tha
Embedded-Embeddable is not mandatory, but it gives you nice OOP perspective of your entities' relationship. Another way to do such a thing - is to use OneToOne
mapping. But in such a case entity WILL be written to separate table (while in case of embedded it CAN be written to the separate table in your DB).
In case of using Hibernate it does not matter if you annotate the field itself (as @Embedded
) or if you annotate the referenced class (as @Embeddable
). At least one of both is needed to let Hibernate determine the type.
And there is a (implicit) statement about this inside the Hibernate documentation, take a look here: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-component
It says:
The Person entity has two component properties, homeAddress and bornIn. homeAddress property has not been annotated, but Hibernate will guess that it is a persistent component by looking for the @Embeddable annotation in the Address class.