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.

Example:

public class person{
    private Name name;
    public Name getName(){ 
        return name;
    }
    public void setName(Name name){
        this.name=name;
    }
     .....
}

public class Name {
    char 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 pidbirthdayinitialfirst and last.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)