Component Mapping


Component Mapping

A component mapping is a class with a member variable that refers to another class. We've encountered this type of mapping when two tables in the mapping file and the set> element is used. In the mapping file, we will now utilise the component> element, and a single table will be used to store the characteristics within the class variable.

A component is a non-referenced object that is included and saved as a value type. The idea of object-oriented synthesis is referred to as "component" (rather than the concept of components at the system architecture level). The Component node in Hibernate can finish the subdivision of complicated data tables. A Component is a logical component of an instance object in hibernate semantics. The primary distinction between a Component and an Entity object is that a Component lacks an identity and is entirely dependent on the Entity object as a logical component.

The dependant object will be mapped as a component in component mapping. An object kept as a value rather than an entity reference is referred to as a component. If the dependent object does not have a primary key, this is the method to utilise. It is called a component since it is operated in composition (HAS-A relation). Let's look at the classes with a HAS-A connection.

package com.javatpoint; public class Address { private String city,country; private int pincode; //getters and setters } package com.javatpoint; public class Employee { private int id; private String name; private Address address;//HAS-A //getters and setters }