[hibernate-dev] question about org.hibernate.engine.ActionQueue

Jia, Yang yang.jia at citigroup.com
Wed Sep 6 21:09:20 EDT 2006


In our application, we need to insert a batch of related objects into db. to improve the performance, we try to use hibernate batch.
I found, enabling 'hibernate.order_updates' in config only makes hibernate to order
        1. the entity update sql
        2. the collection insert/update/delete sql.
this ordering does make these sqls(with the same template sql) running in a batch.

but when we try insert & delete, it doesn't work.
e.g. we have 2 objects: a trade object and a product object. 1 trade -> m product.
when we save a list of new trades, each of which has a corresponding product, the sql will be:
insert into trade_table ...
insert into product_table ...
insert into trade_table ...
insert into product_table ...
insert into trade_table ...
insert into product_table ...
these interleaving sql doesn't enable batch although there are only 2 sqls(just params are diff)

I know we can't use the similar sort to order the insert/delete because they need the order. e.g. trade must be insert before product to ensure not to violate the foreign key constrain.

but I wonder instead of totally ordering the whole list of insert/update whether we could use the following approach?

when trying to add a EntityInsertAction to insertions, (instead of put it at the end of list)
we search the list to see whether there is any EntityInsertAction with the same entityName already in the list.
if no, put this new action to the end of list;
if yes, put this new one right after those EntityInsertActions with the same entityName.

that's, the ordered sql/actions will be:
insert into trade_table ....
insert into trade_table ...
insert into trade_table ...
insert into product_table ..
insert into product_table ...
insert into product_table ...
and in this way, the batch can work.

I attached my test sample program. it seems to work. (it's just for test. so not tuned).

I wonder whether it's viable? or are there other better ways to do it?
Your response will be greatly appreciated.


Regards,
Rick Jia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ActionQueue.java
Type: application/octet-stream
Size: 11418 bytes
Desc: ActionQueue.java
Url : http://lists.jboss.org/pipermail/hibernate-dev/attachments/20060907/6d3e7c3a/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OrderedEntityActionList.java
Type: application/octet-stream
Size: 2065 bytes
Desc: OrderedEntityActionList.java
Url : http://lists.jboss.org/pipermail/hibernate-dev/attachments/20060907/6d3e7c3a/attachment-0001.obj 


More information about the hibernate-dev mailing list