In persistent units we often face a scenario where we think of grouping few similar properties and creating separate persistent entity for them would be expensive. For such situation creating embedded components for grouping such properties makes more sense. The life cycle of such components are managed by the owning components. Embedded components don’t have their own object identity and they are totally dependent on the owning persistent entities. For example let’s take a scenario. We have a Person entity which should create home and billing address. Address will comprise of street, city and zipcode. Either we can add six properties in Person or we can create embedded components for home and billing address. Let’s take a look at the Person POJO.

Here’s the Address POJO.

Finally, let’s take a look at the mapping XML person.hbm.xml for Person:

To add rest of the configuration you can take a look at one of my previous posts on Hibernate here.
Let’s put all the code into action with a main class.