My developer connection home My Developer Connection
knowledgebase for software developers

12. Components

A typical component mapping looks as this:

Definition: Components are Java classes that are populated from selected columns of a parent class' table. This allows second-rank classes to exist within a first-rank class whilst still mapping to a single table for efficiency.

Scenario: We have one first-rank class, Foo, and a second-rank class, FooSecond.


FooSecond Foo.getSecond() // returns enclosed second-rank instance


Hibernate Mapping:
In Hibernate, this could be mapped as follows:

<class name="Foo" table="foo">
     ...
     <component name="second" class="FooSecond">
          <property name="firstName"/>
          <property name="lastName"/>
     </component>
</class>


Table Schema:

Foo

id

firstName

lastName


Here, Foo is mapped using id from table Foo. FooSecond is mapped from the same table using firstName and lastName.

Bidirectionality:
There's no bidirectional relationship available here as there is only one first-rank class involved.

Send mail to webmaster@mydeveloperconnection.com with questions or comments about this web site.
  Send mail to webmaster@mydeveloperconnection.com with questions or comments about this web site.
  Send mail to webmaster@mydeveloperconnection.com with questions or comments about this web site.
  Send mail to webmaster@mydeveloperconnection.com with questions or comments about this web site.