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

[SCBCD5] Lazy values returned from sb

 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,
I have a doubt: what happens if a session bean returns a lazily initialized persistent entity? Are the lazy collections readable?

I have three cases:
1. A stateless session bean invoked by a servlet
2. A stateful session bean invoked by a servlet
3. An inner stateless session bean (local interface) invoked by a session bean
4. An inner stateful session bean (local interface) invoked by a session bean

I have tried the four cases:
1. RuntimeException: no session
2. RuntimeException: no session
3. Ok
4. Ok

Well, I collected the following conclusions, respectively:
1, 2. A remote method returns Objects by copy. Moreover, if the persistence context is transaction type, the returned object is returned as detached
3, 4. Inner session bean share the same injected persistence context. Moreover, local interfaces return objects by reference.

Is all right?

But, if an inner session bean (cases 3, 4) has a transaction persistence context injected, it should always return disconnected objects, but it does not seem to be true: in fact, in cases 3, 4 the object returned by the inner session bean has readable lazy collections.

Can you help me understand? Thanks !
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think there is no relation of lazy relations and basic types with the type of session beans. The lazy fetch objects are available when you use the find operation or JOIN FETCH on these entities (parant entities form lazy object are accessible) or you have referring to non-primary key fields of the lazy object.

More ever I specification explains that the fetchType.LAZY is only hint to the Persistence provider it is not necessary that lazy objects are fetched when they used. I persistence provider can fetch these objects eagerly if they required for the integrity of the application.

Thanks
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mirko and Narendra,

I think that what happens here is:

EJBs in the examples 3 and 4 share the same JTA transaction.
So, they can access the same persistence context.
When it's needed, the lazy loaded relations can be fetch.

I found helpfuls threads in a JBoss forum:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=69112
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=62275

Hope it helps...

Beno�t
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic