Mapping Bean Fields

Introduction

The bean-descriptor maps a bean attribute into one JCR node. Generally, this bean attribute is a also a bean.

Based on our model defined here, the following bean-descriptor is used to map the bean field "pageInfo" (PageInfo class) into the JCR node called "pageInfo".

 				
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.Page" jcrNodeType="graffito:page">
	<bean-descriptor fieldName="pageInfo" jcrName="pageInfo" />
	<!-- other field, bean and collection mapping here !-->
</class-descriptor>
									
<class-descriptor className="org.apache.portals.graffito.jcr.testmodel.PageInfo" jcrNodeType="graffito:PageInfo">
	<field-descriptor fieldName="path" path="true" />
	<field-descriptor fieldName="title" jcrName="graffito:title"/>
	<field-descriptor fieldName="description" jcrName="graffito:description"/>
</class-descriptor>
									
				

In this example, the PageInfo class has a corresponding class-descriptor in the mapping file. By this way, the Persistence Manager can map each PageInfo attributes. It is not necessary to specify the type in the bean-descriptor. The Persistence Manager uses the java introspection to get information on the each bean fields.

Result in the JCR repository

Following our example, the resulting JCR structure can be :

 
/mysite/page1	
  /mysite/page1/pageInfo
       graffito:title = "This is my page title"
       graffito:description = "This is my page description"
  ... other subnodes for page1 ... 
							  

Creating a subnode like this example (mysite/page1/pageInfo) is the default behaviour. See the section Reviewing the bean-descriptor to get other bean-field mapping strategies.