Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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

Entity Bean's state could become stale after creation?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

During the execution of a finder method an EJBObject is created but it's not associated with any bean instance. I understand the reason for this is that the container will still have to load the bean with data from the db when the client invokes a business method in case something changed between the call to the finder method and the call to the business method.

My question is, why the same logic doesn't apply for creates? From what I can gather on pages 328 and 329 of HFEJB, the bean leaves the pool and remains associated with its EJBObject after the call to create ends. Something could also change between creation and the client calling a business method, so isn't the container going to load the bean again before the next business method? Isn't it the same situation as finders?


Thanks!
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Lionel Orellana:
hi all,

During the execution of a finder method an EJBObject is created but it's not associated with any bean instance. I understand the reason for this is that the container will still have to load the bean with data from the db when the client invokes a business method in case something changed between the call to the finder method and the call to the business method.

My question is, why the same logic doesn't apply for creates? From what I can gather on pages 328 and 329 of HFEJB, the bean leaves the pool and remains associated with its EJBObject after the call to create ends. Something could also change between creation and the client calling a business method, so isn't the container going to load the bean again before the next business method? Isn't it the same situation as finders?


Thanks!



The finder method is invoked on the home object, not on the EJBObject. Suppose you are in this scenario:

1) You've just created an entity and have got a reference to an entity's EJBObject stub

2) Supposed in this moment the database is not locked (let's say because the container finished the create transaction), someone changes the value in the record you've just added

3) Not aware of the changes, you invoke a business method on your EJBObject

The container will start a transaction (ensuring that the underlying persistent state cannot be corrupted - by, let's say, asking the db to lock a record), will load the bean with the latest record value and will executed the business method, updating the database with the bean's last state and ending the transaction. As you can see there is no risk for the container in letting you with a reference to a just created entity bean.
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic