Working with the ADF Business Components: Programming ADF Entity Objects

When you develop a Java application, you will end up mapping Java objects to relational data while managing transactions and locking mechanism. This is where ADF BC steps in. Beyond providing much different functionality, the ADF Business Components make creating and using the model layer fast and easy to manage through a declarative interface. ADF framework provides easy binding of JSF interfaces to ADF BC using the ADF Model layer. We can visually create business components using wizards in JDeveloper and then drag it onto a JSF page.

ADF entity objects are business components that implement the business model, which are data and rules. Entity object definition maps to a single object in the data source. In most cases, these are tables, views in your database.

Database interaction and operation of an entity object can be achieved without using custom Java code. However ADF uses MVC (Model/View/Controller) architecture, which means there is a back-end code implemented separately. That can be complex business logic or utility classes. This can raise a need of accessing ADF BC programmatically with Java code. In that case we will need to generate Java classes for the entities that require custom behavior.

When we create an Application Module and Business Components from the data source, initially we don’t have any Java class generated for us. If we want to inject a custom behavior, we must generate the Java Class for our Entity Object. Here is how we do it for Employees Entity Object;

  • · Right click on Employees.
  • · Then go to Java option.
  • · Click on Java Classes.
  • · Make sure Generate Entity Object Class and Include Accessors are selected.
  • · Then you can select Create Method, Remove Method or Data Manipulation Methods as you need.
  • · Once you hit ok is created. will have all the getter and setter methods along with the create(…) remove(…) and doDML(…) methods. Then you can modify or embed your own logic to those methods. Below is a method that creates a new employee and return its new id.

 public long createEmployee(String name,
String description) {
 EntityDefImpl employeesDef =
 EmployeesImpl newEmployee =
 * newEmployee.set ....
 try {
 catch (JboException ex) {
 throw ex;
 Number newIdAssigned =
 return newIdAssigned.longValue();

If you have any question please feel free to post a comment.



Nice post and explanation! What if I want to update an existing employee? Suppose that I want to programatically calculate the employee salary while updating it (only while updating, a new employee has default salary). Can you help with that? Thanks in advance

Posted by Renan Castro on June 09, 2011 at 04:04 PM CEST #

If you want to update employee salary and If you want programmatically to calculate the value then you should follow the steps that is described in the blog. However this time make sure when generating Employees Entity Object Class select Data Manipulation Methods. This will generate the doDML(...) method. Then you can override this method and do your custom calculation within this method. Below you can find a sample code.

* Custom DML update/insert/delete logic here.
* @param operation the operation type
* @param e the transaction event
protected void doDML(int operation, TransactionEvent e) {
if(operation == DML_UPDATE){
// do your custome calculation, call method to do it, etc.
this.setSalary(new Number("someValueHere")); //You can call a utulity method also
}catch(Exception handleExceptionHere){
super.doDML(operation, e);

Posted by guest on June 17, 2011 at 05:10 AM CEST #

Thanks for your answer, I'll try it later!

Posted by Renan Castro on June 20, 2011 at 04:22 PM CEST #

Hi, can you give a example to get a object by key in my java class?

Thank you

Posted by Nelson Maia on November 09, 2011 at 09:14 AM CET #

sir can you give some example of creating custom validation method on entity object level and calling it from the application like validation of email address.

Posted by Naeem on September 05, 2012 at 07:08 AM CEST #

small question ,

i have a Java class in my View Controller and i want access that java class in model can u suggest the best way

i already tried the dependencies in Properties window but no luck

Posted by guest on November 02, 2012 at 02:07 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

Oracle ECEMEA Partner Hubs Migration Center Team

We share our skills to maximize your revenue!
Rapidly and successfully assist you to adopt and implement the latest of Oracle Technology in your solutions.

Stay Connected


« February 2015