ADF Business Components: using Transient Attributes in Entity Objects

If you have multiple ADF BC View Objects that are defined on the same Entity Object, and these View Objects need to have the same transient attribute, then it is more convenient to define that transient attribute at the Entity Object level. If you do, this article describes how you can optimize the performance.

Example Situation: Entity Object X has 2 Name attributes: an English Name and a French Name. Depending on the user context, either the English or the French name must be displayed. View Objects A and B are both based on Entity Object X, and need to display the name in English or French, depending on the user context.
You could define a transient attribute in both the VO's, but you prefer to define a transient attribute in the EO and include that attribute in both VO's.

How to Create a Transient Entity Attribute: Open the Entity Object editor, and select the Attributes category on the left hand side. On the bottom of the right hand side, click the button New. Uncheck the Persistent checkbox. For our example, let's assume we call this attribute 'Name'.

Make sure the EntityImpl Java Class is generated, with accessors. Open that Java class and customize the getName() method. Depending on the user context, return either getNameEnglish() or getNameFrench().

Possible Performance Problem: Suppose you access View Object A, and it performs its database query. Since the queried data are mapped to Entity Attributes, they are stored in the Entity cache. Assume that you access the Name attribute of View Object A, which is mapped to the transient Name attribute of Entity X. The EntityImpl.getName() method calls getNameEnglish().
Now if the value of NameEnglish is not found in the Entity Cache, the Entity Object is forced to query the database to get the value of database column Name_English for this row. To make it worse, for each new row where getName() is called, again a database round trip is made. This way many extra database queries may be performed, slowing down the application.

Easy Prevention of this Problem: Make sure that ViewObjects A and B include attributes NameEnglish and NameFrench. This way the query execution for A and B will be a little bit slower, but it will retrieve NameEnglish and NameFrench for all the rows in one database round trip and store them in the Entity cache. Then, when getName() is called, the values of NameEnglish and NameFrench are instantly available, avoiding the need for SQL queries performed by the Entity Object.

Written by Sandra Muller, last updated on May 12, 2006
Powered by
Movable Type and Oracle