• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

[SCBCD5] Lazy values returned from sb

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic