4 Replies Latest reply on Oct 10, 2001 10:33 PM by John Baker

    custom findAll()

    jeff seaman Newbie

      Is there any way to customize findAll() using CMP. What I want to do is return the details of all the entity beans in a collection of value serializable objects instead of returning collection of entity beans as the return for a findAll(). I thought what I could do is create a custom finder and then within the finder do a findAll() and for each entity bean returned create a new value detail object. This raises another question - Is there a easier way to get the home interface of an entity bean from within the bean itself without having to do a JNDI lookup for the home interface. I've got to think there is an easier way.


      Jeff Seaman

        • 1. Re: custom findAll()
          David Jencks Master

          No. A collection valued finder has to return a collection of remote interfaces. You can do what you want as a non-finder method on a session bean.

          The home interface is available by remembering the (entity or session) context, getting the EJBObject from it, and getting the EJBHome from that. I'm not sure if this is simpler than using jndi.. it doesn't require knowing the name it's bound under anyway

          • 2. Re: custom findAll()
            Verdi March Newbie

            try this:
            <!-- override finder -->


            type_id ASC

            • 3. Re: custom findAll()
              Paul Austin Newbie

              David was right the findXXX methods in Entity allways return a collection of the proxies that implement the remote interface. The implementations of the ejbFindXXX methods return a list of the primary keys of the entities to return. The container converts these primary keys into the proxies that the client sees from the findXXX method.

              To implement what you are suggesting you would need to create a Sateless Session Bean with a method that invokes the findXXX method and then has a loop that loops through the collection and invokes the method to get the serialized version of the entity from the remote interaface and populates a new collection with the serialized versions that it returns to the client.

              The other poster was partially correct in that you can provide a custom version of findAll if all you need to do is change the query or order of the results. But this would not allow you to do what you require.

              Hope this helps,

              • 4. Re: custom findAll()
                John Baker Newbie

                Give up with entity beans for large quantities of things!! I use my own persistance mechanism that maps tables,queries,updates,inserts etc straight to pass-by-value objects and allows parameter substitution etc. That way I remain DB independent but don't have the draw-bracks of entity performance/lots of entity-value translation code. All the mappings are in elsewhere in XML and the beans support removeByXX methods, updateXXX methods and anything else that I might need ahead of the evolving standards. Entities are fine when small numbers are involved at one time.

                My session bean code ends up easy to follow and small i.e

                TNodeInfo[] getNodeInfo() throws Blah...
                BeanFindMethod finder = (BeanFindMethod)

                return (TNodeInfo[])finder.findArray(getDataSource(), new Object[] { regionId });

                Where the XML (loaded as a resource) describes the bean fields, columns, SQL for different methods etc.
                and the result set get turned into an array of TNodeInfo value objects in one operation.

                <sql-statement>select * from TNODE where REGION_ID = :id</sql-statement>

                Saves a lot of hassle, the performance is great and you can add whatever new types of method you like.

                Hope this helps