Entering content frame

Process documentation Creating Dependent-Value Persistent Fields Locate the document in its SAP Library structure

Purpose

Use dependent-value persistent fields when you want to encapsulate several attributes in one persistent field. The attributes in most cases will be used together, that is they are meaningful and are used in the business logic of the application as a whole. These attributes are declared as fields in the dependent-value class.

The dependent-value class, which corresponds to the persistent field, is a concrete class. It must be serializable. Dependent-value persistent fields can be stored in one column in the database table or each persistent field of the dependent-value class can be stored in a separate column. If the persistent fields of the dependent-value class are stored in separate columns, then the dependent-value class must be defined as public, and must have an empty constructor. The dependent-value class cannot be abstract. Its persistent fields must also be defined as public.

Dependent-value classes can be used internally within the container-managed entity bean, or they can be exposed in the remote or local interfaces of the bean.

Process Flow

...

       1.      Create the dependent-value class:

                            a.      Choose File ® New ® Other

                            b.      On the left pane of the wizard, choose Java, and on the right pane, select Class

                            c.      Choose Next

                            d.      In the Source Folder field, browse and enter the name of the EJB project that contains your container-managed entity bean.

                            e.      In the Package field, specify the package of the dependent-value class.

                              f.      In the Name field, enter the name of the dependent-value class

                            g.      Choose Add to add a new interface.

A dialog box appears. The dependent-value class must implement the java.io.Serializableinterface.

                            h.      In the dialog box, add java.io.Serializable.

The interface appears in the Interfaces pane.

                              i.      From the Modifiers options, select public

                              j.      In the Superclass field, enter java.lang.Object.

                            k.      Select the Inherit abstract methods option

                              l.      Choose Finish.

The dependent-value class is created.

                          m.      Specify the fields of the dependent-value class in the source code

Example

package com.sap.ejbproject;

 

import java.io.Serializable;

 

public class Address implements Serializable {

   public String street="One Ave.";

   public String number="22a";

   public String city="Sofia";

}

 

       2.      Create the entity bean’s persistent field

                            a.      In the Fully Qualified Name field, enter the name of the dependent-value class. You must specify the package of the dependent-value class, too.

Result

When you specify the O/R mapping of the persistent field that corresponds to the dependent-value class in the NetWeaver Developer Studio, the fields of the dependent-value class automatically appear as sub-nodes in the cmp-field tree structure. You can map these fields to the corresponding columns in the database table. It is also possible to map the persistent field to one column in the database table. For more information, see Mapping Persistent Fields (cmp-fields).

 

 

Leaving content frame