Your problem is that the iteration is not on a transaction.
If you put all your calls to UPDATE methods (setXXX) into a one transaction (the finder adn the iteration), the SQL generated are very small and iteration over the collection is very fast.
In my experience, this trivial operation is surprisinglly difficult to code and get right in practice. Jaime is correct in that you need some transaction management.
However, you need to realise that if you attempt to perform this update in a single transaction your application is likely to lock up until it is finished (maybe a minute or two?). Every entity in that collection will get sucked into the transaction - so every other client that tries to access it will block on a transaction lock until it is complete. Is a minute too long to wait for a web page?
I think that it is acknowledged that CMP entity beans are not good at bulk operations like this, mainly because the container overhead results in the operation taking four or more times longer that it should. You could consider using direct JDBC as an alternative for this operation.
In the interim, I have used the following pattern:
1. Define a method in, say, a session bean that has a trx attribute of "NotSupported";
2. Define a special setter method in the entity bean with an implementation that just invokes the abstract setter and give it a trx attribute of "RequiresNew";
3. Assign the finder method of the entity a trx attribute of "RequiresNew".
4. from the session bean, invoke the finder which should return all entities in a single transaction.
5. Iterate over the collection, invoking the special setter method on the entity, one trx at a time.
This will take a little longer than performing it in a single trx, but your system will remain usable while it it executing.
I need more info on this issue;
can you explain it in detail or could you point to some chapters in the jboss documentation or j2ee specs which i need to look to understand this issue.