Finder methods for entity bean


EJB programming & troubleshooting: Finder methods for entity bean

  1. Finder methods for entity bean (3 messages)

    Can I call finder method from the implementating entity bean class itself to find other instances of same entity bean?? My final aim is to create a binary tree in 0which each node will be represented by an entity bean instance. In the Entity bean I would like to place a method which will look for its child to form the tree. So that if I call this method on root node it will return the whole tree. I know java doesn't restrict me to do so, but is it advisable to follow this practice??


    Threaded Messages (3)

  2. Finder methods for entity bean[ Go to top ]

    IIRC, you can call the finder methods from an Entity Bean. Get the home reference using getEJBHome() or getEJBLocalHome as it suits you.

    But a word of warning: The load time will increase exponentially as the number of nodes below any given node increases. Perhaps you should consider lazy loading your tree. An example of what can happen:

    Let's suppose that you have an entity bean pool of maximun 3 beans, and the tree have 7 nodes in a perfectly balanced tree. (short example to fit the page)
    Let see the evolution of the pool when you load the root:

    node Entities In pool Operations
    root root, root-1, root-2 3L
    root-1 root-1, root-1-1,root-1-2 2S, 2L
    root-1-1 root-1-1,root-1-1-1, root-1-1-2 2S, 2L
    root-1-1-1 root-1-1,root-1-1-1, root-1-1-2
    root-1-1-2 root-1-1,root-1-1-1, root-1-1-2
    root-1-2 root-1-1,root-1-1-1, root-1-2 1S,1L
    root-1-2-1 root-1-2,root-1-2-1, root-1-1-2 1S,1L
    root-1-2-2 root-1-2,root-1-2-1, root-1-2-2 1S,1L

    etc.. (this was larger than I thought)

    So far, to read 8 nodes it performs 10 loads and 7 stores. This behavior will start to happen as soon as your EntityBean pool reaches it maximun allowed, as for each new node you load a node will need to be stored to reuse the instance, and as you're reading the tree recursively when you return from reading the childs you'll need to reload the parent node.

    BTW, which type of Entity Bean do you plan to use?

    Hope this help,
  3. Finder methods for entity bean[ Go to top ]

    hmm, sorry for the bad formatting of the table, it was not expected :(
  4. Finder methods for entity bean[ Go to top ]

    Thanx for your suggetions.
    I will keep in mind these facts while design
    I am planning to use CMP