-
1. Re: 3.2.1, Iterator.remove() on Collection
benholland May 28, 2003 6:51 AM (in response to dcrot)I noticed the same behaviour on 3.0.6.
I got round it by doing
Set accounts = Customer.getAccounts();
accounts.remove(localAccount);
Jboss then removed the link from the account
to the customer.
Not sure if you are right about the illegal state exception depends on the type of iterator I think. -
2. Re: 3.2.1, Iterator.remove() on Collection
raja05 May 28, 2003 8:17 AM (in response to dcrot)Collection c = ejbSelectOrders();
Iterator i = c.iterator();
while(i.hasNext()) {
i.next();
i.remove();
}
would not call your EJB as the next() returns an Object and not the localejb. Only if you cast it, you get a EJBLocal object.. -
3. Re: 3.2.1, Iterator.remove() on Collection
dcrot May 28, 2003 6:09 PM (in response to dcrot)Ben,
the EJB spec states in 10.3.6.1 that "... the bean provider must not modify the containmer manager collection while the iteration is in progress in any way that causes elements to be added or removed, other than by the Iterator.remove method... or a IllegalStateException should be thrown by the container..."
Doing it your way means that I need a reference to an entity bean to start with, in my case I'm blindly deleting in all records in the collection.
thanks,
Dean -
4. Re: 3.2.1, Iterator.remove() on Collection
benholland May 29, 2003 11:19 AM (in response to dcrot)point taken on the exception front.
To delete a collection in cmr just set the collection to a zero sized hashset. JBoss will remove the relationships from the RDBMS. If you configure the db or jboss to cascade delete it will remove the rows as well.
I just tried it it works. -
5. Re: 3.2.1, Iterator.remove() on Collection
dcrot May 29, 2003 8:41 PM (in response to dcrot)Ben,
I've been treating ejbSelect's as cmr's, which they arent, hence this is the reason why iterator.remove() doesnt work. For example, the Collection implementation for an ejbSelect is java.util.ArrayList, whereas the implemetaiton for a cmr is RelationSet.
When you say "set the collection to a zero size hashset", are you talking about the Collection.clear() method?
As for cascade-deletes, I cant use them for my many-to-many relationships, and I dont want the db to perform the deletes, as I'd then have to use commit option b or c.
thanks,
Dean -
6. Re: 3.2.1, Iterator.remove() on Collection
benholland May 30, 2003 3:52 AM (in response to dcrot)Dean,
It's not pretty:
CustomerLocalHome home = (CustomerLocalHome) ctx.lookup("local/Customer");
CustomerLocal cust =
home.findByPrimaryKey(new CustomerPK( customerID));
cust.setAccounts(new HashSet(0));
I dont have experience of ejb select, let me know if it works. -
7. Re: 3.2.1, Iterator.remove() on Collection
kgodbole Jul 9, 2003 10:58 AM (in response to dcrot)I am using JBoss 3.2.1 and have found that if you try to remove from the collection returned by a cmr-get method, you get IllegaStateException. This is in the specs, as mentioned by Dean.
However, if you convert the collection to ArrayList it somehow works.
Collection c = ejbSelectAllOrders();
ArrayList al = new ArrayList(c);
for (Iterator it = al.iterator(); it.hasNext(); ) {
((OrderLocal) (it.next())).remove();
}
Any explanations will be very welcome.
Thanks.