Powered By Blogger

Wednesday, May 30, 2012

The RL function getFactByType found more than one instance of the fact type

In this article we discuss one of rules invocation error we encounter frequently during development.
The error mentioned in post title generally comes because of rules data modeling mistake.

Following are some rules data modeling mistakes we may do
  • Assuming rule firing order, but rules execution order is not predefined by OBR engine
  • Asserting multiple facts of same type 
In OBR, before decision function is about to return, it will check for a fact in the working memory whose type matches the type defined as the output of the decision function. If it finds multiple facts that match the type,then it doesn't know which fact to select and  it will throw an above mentioned exception.
Here magic is input and output facts are matched based on their types but not on names.

Best and bit tedious way to resolve the error is, go back and re visit all your rule actions and make sure your code is not asserting same fact repeatedly and unnecessarly.
Most of asserts can be replaced by modify  which will modify same fact instance.

Second solution would be go to decision function Outputs section and mark  List option.What we are saying is duplicates are allowed and it returns all matching type output facts. It is our BPEL code responsibility to check and use appropriate fact in decision making process.


6 comments: