Skip to main content

Throwing ValidationException from the beforeCommit() logic !

If you have some validation logic added to beforeCommit() of the ApplicationModuleImpl or EntityObjectImpl and you face strange rollback behavior(Entity Objects are losing the modified data) while committing data second time after correcting the validation error, then this post is for you :)

From Developer's Guide....
8.5.2 How to Validate Conditions Related to All Entities of a Given Type

If your beforeCommit() logic can throw a ValidationException, you must set the jbo.txn.handleafterpostexc property to true in your configuration to have the framework automatically handle rolling back the in-memory state of the other entity objects that may have already successfully posted to the database (but not yet been committed) during the current commit cycle.

Java Option : -Djbo.txn.handleafterpostexc=true


Xahar said…
Hi Jobinesh,

What is the benefit of using an Entity Object over doing table manipulations from back-end?
Jobinesh said…
Well the question here can rephrased as "Why do you need ORM tools like ADF BC/Hibernate etc"?. As this has been discussed in lot of places, I'm just copying some discussions I noticed in net
Hi Jobinesh,

I am sorry to bother you with some specific implementation. I like your posts and follow the posts regularly. I thought you can help me in resolving the issue.

Is there any possibility of catching model validation failures in valuechangelistener code.


I am coming from the UI. We have a requirement to call a service when the value is changed after making sure the data of the field is correct (The validation depends on some other db queries too). Once the data is validated, we have to set other attributes of the entity object. Then we have to make a service call on application module if all the validations are passed and the required attributes are set with out any problem.


We have implemented the validations at the attribute level on the entity object and implemented setAttribute method to set other required attributes.

We have a valuechagelistener for that field in UI and we are calling service method after calling valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance()).

But we have to prevent the service call if the validation on the model layer fails. How can I capture the error messages and prevent the service call execution.

If I am doing some thing wrong with the implementation, can you please suggest best way to meet the requirement.

Thanks and Regards,

S R Prasad
Jobinesh said…
ValueChaneEvent happens before the model update and validation. One work around is to queue the vent for later phase, something as shown below
public void test(ValueChangeEvent valueChangeEvent) {

if(!valueChangeEvent.getPhaseId().equals(PhaseId.INVOKE_APPLICATION) ){
//Your business logic goes here...

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…