Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Collections and Iterators in CMP transactions

 
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
 
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
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic