• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Entity Bean instances when mapped to a database table

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an entity bean mapped to a database table. There are 1000 records in the database table. If i select all the records using SELECT * FROM TABLE. How many instances of the entity bean will exist ? Will there be 1000 instances of the entity bean in memory ? I just want to know what will be the representaion of the records in memory for my Query ?

Thanks...!!!
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No that's not the case. The container maintains a free pool of entity beans when it initializes. The pool can grow or shrink, as the container needs to improve the performances or to preserve its internal resources. In order to serve an ejbFinder() method, the container will use an instance from the pool and won�t create any additional instances after or before the finder returns. So it doesn�t matter whether your select query returns 1000 records or no records at all. The container will only return a collection of primary keys that match the records in your database.
 
Raj Jindal
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's fine that the container will return the collection of primary keys correspondingto the SQL query. What will be the internal representation of records in the memory. When i need some record Will i need to use ejbFind() method again.
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not understanding this statement 'collection of primary keys' ???
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am not understanding this statement 'collection of primary keys' ???


Hi Kri,

Please read it as a collection of remote interfaces.


What will be the internal representation of records in the memory. When i need some record Will i need to use ejbFind() method again.


It might be no record representation in memory, after the finder runs. Here there are my thoughts: entity EJBs won�t leave the pooled state after a finder. The finder only returns a list of remote interfaces to the client. In a way a found bean follows the same protocol as a passivated bean; it is activated when the client invokes a business method on that bean. My point is that after the finder runs I don�t expect much memory allocation or re-allocation to happen within the container. Does the container feel that it needs more bean instances in the pool? That�s fine though, the container will create more instances. The point is that a bean instance is a lightweight component and it doesn�t waste resources (sockets, memory, connections, etc). However if the client loops through all remote interfaces returned by the finder and invokes business methods, then the story will drastically change. The container has no choice but to activate all those bean instances; did the finder returned 1000 beans? Then the container will instantiate 1000 heavyweight bean objects and memory will be consumed, sockets will be used, locking will be acquired, etc. After this point you might think that your records are represented in memory exactly as a set of 1000 EJB objects. Well this might or might not be true, because while the client is looping through all the 1000 beans invoking business methods, the container might decide to passivate some of them. However if you enlist your looping within a transaction then guaranteed you�ll have 1000 beans in memory.
reply
    Bookmark Topic Watch Topic
  • New Topic