This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic