Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections and Iterators in CMP transactions

 
Jehan Jaleel
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the 2.0 spec it says...
"It is the responsibility of the Container to throw the java.lang.IllegalStateException
when a method of the java.util.Collection API is used to access a collection-
valued cmr-field within a transaction context other than the transaction context in which
the cmr-field was initially materialized."
It has a similar point about Iterators. I am not sure what is meant here, can someone shed some light on this.
thanks,
Jehan
 
Andrew Perepelytsya
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.
Let's say, your client (servlet, most often) calls a bean and gets a collection of local-refs from the CMR field. Let it be User->Credit Cards
Now, if you try to iterate over credit card interfaces in the servlet, you will get the mentioned exception.
To rehash - you can get such a collection in a session bean method, and you must iterate over it in that same thread of execution (generally, it will be the same business method).
There are more complex issues with client initiated transactions, but most often these cases do not follow the best-practices design.
A general solution is to use a DTO/VO (Data Transfer Object/Value Object) as a return value for your session bean method. Sun currently refer to DTO simply as TO.
More info at http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html
While this is not required for exam right now (it might be, who knows), it's imperative you know these patterns for practical EJB projects.
Good luck
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic