What is component mapping in hibernate?

By: Emiley J. Viewed: 153197 times    

A component is a contained object that is persisted as a value type ,not an entity reference.

Example:

public class person{

private Name name;

public Name getName(){ return name;}

public void setName(Name name){this.name=name;}

.....

}

public class Name

{chat initial;

String first;

String last;

public char getInitial(){return initial;}

public void setInitial(char initial){this.initial=initial;}

.......//first,last

}

Now 'Name' may be persited to the component of 'person'

in hbm:

<class name="eg.Person" table="person">
    <id name="Key" column="pid" type="string">
        <generator class="uuid"/>
    </id>
    <property name="birthday" type="date"/>
    <component name="Name" class="eg.Name"> <!-- class attribute optional -->
        <property name="initial"/>
        <property name="first"/>
        <property name="last"/>
    </component>
</class>

The person table would have the columns pid, birthday, initial, first and last.

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)

Comment on this tutorial