A "component" in Hibernate is an object persisted as a value, not an entity reference. For example, suppose you have a
Car class, like this:
//class Car
public class Car {
private String id;
private String type;
private Skills skills;
public String getId() {
return id;
}
private void setId(String id) {
this.id=id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Name getSkills() {
return skills;
}
public void setSkills(Skills skills) {
this.skills = skills;
}
......
}
And the
Skills class looks like this:
//class Skills
public class Skills {
int speed;
String gearBox;
public int getSpeed() {
return speed;
}
void setSpeed(int speed) {
this.speed = speed;
}
public String getGearBox() {
return gearBox;
}
void setGearBox(String gearBox) {
this.gearBox = gearBox;
}
}
Here is the Hibernate mapping for the
Car class:
<class name="Car" table="CARS">
<id name="id" column="car_id" type="string">
<generator class="uuid.hex"/>
</id>
<property name="type" type="string"/>
<component name="Skills" class="Skills">
<property name="speed"/>
<property name="gearBox"/>
</component>
</class>
Notice the
<component> tag. Now the
CARS table will have the following columns:
car_id, type, speed, and
gearBox.