Hi
Consider that i have one entity bean with relation to 3 or 4 other entity beans, I want to read some information from this group of entites, I want to know is it better to write a EJBSelect method in one them and use that method for doing this or it is better to do it from my client (for example servlet) and read that information with a FOR and iterate over collection of them.
tell me which one is more efficient [Time and Performance]
Thanks
--Amir Hossein
-
ejbSelect() Method ! (5 messages)
- Posted by: Amir Hossein Hormati
- Posted on: November 16 2003 14:48 EST
Threaded Messages (5)
- ejbSelect() Method ! by Paul Strack on November 17 2003 07:04 EST
- When ? by Amir Hossein Hormati on November 18 2003 02:54 EST
-
When ? by Paul Strack on November 18 2003 08:21 EST
- Thanks by Amir Hossein Hormati on November 19 2003 10:06 EST
-
When ? by Paul Strack on November 18 2003 08:21 EST
- When ? by Amir Hossein Hormati on November 18 2003 02:54 EST
- ejbSelect() Method ! by Goprinks R on November 24 2003 17:05 EST
-
ejbSelect() Method ![ Go to top ]
- Posted by: Paul Strack
- Posted on: November 17 2003 07:04 EST
- in response to Amir Hossein Hormati
The best solution is to write a session bean with the logic to invoke all the entities and assemble your data. The session bean can store the data in lightweight value objects. The client can then call the session bean. This is generally referred to as the Session Facade pattern.
http://java.sun.com/blueprints/patterns/SessionFacade.html
The reasoning behind this pattern is:
1) If the client invokes the Entities directly, it is horribly ineffecient (you can end up with dozens of extraneous database calls).
2) It is often a bad idea for one Entity EJB to invoke a different Entity except for very controlled ways (like Container Managed Relationships). -
When ?[ Go to top ]
- Posted by: Amir Hossein Hormati
- Posted on: November 18 2003 02:54 EST
- in response to Paul Strack
Thanks for your answer , but actually my question is about when i should use ejbSelect() and ejbHome methods, consider that i'm talking about cmp and container managed relationship,
please compare this in 2 conditions :
1-do my reads in a session bean from 3 CMPs with relationship
2-write a ejbselect method in one the CMPs and then call this method from sessoin bean
Thanks
I'm looking forward for my answer ;)
thanks -
When ?[ Go to top ]
- Posted by: Paul Strack
- Posted on: November 18 2003 08:21 EST
- in response to Amir Hossein Hormati
An ejbSelect() method is useful when you want to retrieve exactly one fiel from an Entity bean. If you only need a single field from a given Entity, the ejbSelect() can be more efficient. If you need multiple fiels, I would use the entities normal getter methods instead.
As for ejbHome() methods, they are more or less functionally equivalent to methods in your stateless session beans. Personally, I am a bit suspicious of them, because they are obscure and new in the spec, and therefore less likely to be as well tests as session beans. That is a personal bias, though. -
Thanks[ Go to top ]
- Posted by: Amir Hossein Hormati
- Posted on: November 19 2003 10:06 EST
- in response to Paul Strack
Thanks paul for your aswers, -
ejbSelect() Method ![ Go to top ]
- Posted by: Goprinks R
- Posted on: November 24 2003 17:05 EST
- in response to Amir Hossein Hormati
Hi,
EjbHome method are used for
1. These methods pertain to the overall table or atleast more than one entity and thus cannot be put into Remote Interface . E.g Total number of employees in the company. To achieve the same thing without home method we would have been forced to put a method FindAllEmployees() and then determine the size of the collection returned.This is inefficient as it is a memory hogger.
2.Because they do not pertain to any specific entity for there execution a bean lying in pool is used.
EjbSelect() method is used for
Its a finder method in CMP Bean that is transparent to client and is used solely by the bean code. Its useful because its return type need not only be collection of Primary Keys. It can be any collection of any CMP field as well. E.g If in execution of some method we need total salary of all the employees then we can use a select method that can return us collection of Salary field whereas using Finder method would be cumbersome and a memory hogger.
Regards,
Rinku