groovenarula | 3 Jul 2012 16:21
Favicon

ConcurrentModificationException loading facts from db (Hibernate).

In my use case, I have ~ 200,000 rows in a table that I need lookup in order
to price an item. Rather than load the entire table into working memory,I'm
trying load the relevant rows (based on a matching criteria) and load those
as facts and then have my rules evaluate the loaded facts. Based on that
I've got the following rule :

rule "Load pricelist"
	salience 10000
	when
		
		$priceUnit : PriceUnit()
		not ( exists Pricelist( id.prodid == $priceUnit.prodid ) )
		$unitPrices : ArrayList() from collect ( Pricelist() from
PricelistUtilities.getPriceLists($priceUnit.prodid) ) 
	then
		for( Pricelist  priceList : (List<Pricelist>) $unitPrices ) {
			insert (priceList);
		}
end

In the rule above - 'PriceUnit' is the unit that I'm trying to price. And
'Pricelist' is the facts that I'm trying to fetch from a table based on the
prodid matching and inserting those into WM. The
PricelistUtilities.getPriceList returns a list of price list items that
match the 'Product id' (prodid). In the RHS, all I'm trying to iterate over
the list of pricelists and then insert those into WM.

When I execute the rule above, I can see that the rule is executing the
'select' to load pricelists :

(Continue reading)

Wolfgang Laun | 3 Jul 2012 16:34
Picon

Re: ConcurrentModificationException loading facts from db (Hibernate).

$unitPrices : ArrayList() is bound to a collected list. The first insertion of
a fact from this list cancels the activation and results in this ArrayList
becoming modified.

Copy the List before iterating over it, e.g.

    ArrayList copiedList = new ArrayList( $unitPrices );
    for( Pricelist  priceList : (List<Pricelist>)copiedList ) {
 			insert (priceList);
   }

-W

On 03/07/2012, groovenarula <gnarula1 <at> la-z-boy.com> wrote:
> In my use case, I have ~ 200,000 rows in a table that I need lookup in
> order
> to price an item. Rather than load the entire table into working memory,I'm
> trying load the relevant rows (based on a matching criteria) and load those
> as facts and then have my rules evaluate the loaded facts. Based on that
> I've got the following rule :
>
> rule "Load pricelist"
> 	salience 10000
> 	when
> 		
> 		$priceUnit : PriceUnit()
> 		not ( exists Pricelist( id.prodid == $priceUnit.prodid ) )
> 		$unitPrices : ArrayList() from collect ( Pricelist() from
> PricelistUtilities.getPriceLists($priceUnit.prodid) )
> 	then
(Continue reading)

groovenarula | 3 Jul 2012 19:08
Favicon

Re: ConcurrentModificationException loading facts from db (Hibernate).

That worked. Thanks for clearing this up.

--
View this message in context: http://drools.46999.n3.nabble.com/ConcurrentModificationException-loading-facts-from-db-Hibernate-tp4018431p4018437.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Gmane