RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Oct 30, 2007



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Mapping a Component in Hibernate

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) {
    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"/>
    <property name="type" type="string"/>
    <component name="Skills" class="Skills">
        <property name="speed"/>
        <property name="gearBox"/>
Notice the <component> tag. Now the CARS table will have the following columns: car_id, type, speed, and gearBox.

Leonard Anghel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date