Programming Tutorials

What is component mapping in hibernate?

By: Emiley J. in Hibernate Tutorials on 2008-09-02  

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


public class person{
    private Name name;
    public Name getName(){ 
        return name;
    public void setName(Name name){;

public class Name {
    char initial;
    String first;
    String last;

    public char getInitial() {
        return initial;

    public void setInitial(char 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"/>
    <property name="birthday" type="date"/>
    <component name="Name" class="eg.Name"> <!-- class attribute optional -->
        <property name="initial"/>
        <property name="first"/>
        <property name="last"/>

The person table would have the columns pidbirthdayinitialfirst and last.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)