What is component mapping in hibernate?

By: Emiley J.  

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){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;}



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 pid, birthday, initial, first and last.

Most Viewed Articles (in Hibernate )

Latest Articles (in Hibernate)

Comment on this tutorial