Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

choosing between home business methods and finders

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends!
While designing the home interface how do you choose between home business methods and home finder methods. I know the later retrieves the remote references and client will have to do remote calls to get the data, which will have network overhead. Some say that just to give the data to the client we can use home business methods to return objects other than remote references. Then what is the use of home finders?
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sreenath ,

You can use finders defined in the local home interface. These finders don't throw RemoteException and they return the local (not remote) interfaces as well (therefore they must be defined). You are also not forced to narrow, simply casting will be enough.
Regards.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Valentin!
I am sorry you misinterpreted my question. I was not talking about local or remote interfaces. I was talking about choosing between home business methods and home finders, which can be there both on remote and local home interfaces.
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

While designing the home interface how do you choose between home business methods and home finder methods. I know the later retrieves the remote references and client will have to do remote calls to get the data, which will have network overhead. Some say that just to give the data to the client we can use home business methods to return objects other than remote references. Then what is the use of home finders?



If I have understood your question properly than I will put it like this-

finders are used in entity beans to return data from database. Business methods can be used in session beans where one can process the data returned from entity beans finder methods and return to the client only the processed data rather than the whole data. The interaction between session bean and entity bean can be local when they both deployed on same ejb container hence less traffic overhead. One session bean can interact with many entity beans in same business method so the client need made many remote references to diff. entity beans separately rather just one remote reference to session bean business method which in turn can make just local references to finder methods of diff. entity beans.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK!
let me make myself more clear this time. I think there is something wrong with my communication skills

Entity Bean home interface can have creaters, finders and home business methods.

1) creater or rather create methods are used to create a row in the database.

My point comes below.

2) finder methods : Client uses finder methods to get a collection of( or one remote ref if it is find by primary key) of the remote references. To get to the data he wants, he iterates through the collection and calls business methods of the remote interfaces. This can be network heavy. If we have 5000 remote interfaces in the collection, it will be atleast so many number of remote calls!!!

3) home business methods : Client uses these methods to get to data directly. This happens only once. Compare 5000 remote calls to one!!

Now the question is when to choose between entity home finders and entity home business methods. If the home business methods returning a collection of data are reducing the network traffic, why do you want to use finders, except for findbyprimarykey?

Thanks
 
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 believe I got it this time :-)
First of all finder methods come for "free", when CMP is used. Second of all the bean life cycle is internally managed by the container, transitioning beans from the pooled state to the method ready state when a finder is called, etc. Business methods acting like finders will return POJOs which will defend the purpose of implementing the persistence layer through ejbs. Third of all:


To get to the data he wants, he iterates through the collection and calls business methods of the remote interfaces. This can be network heavy. If we have 5000 remote interfaces in the collection, it will be atleast so many number of remote calls!!!


Is not quite true. It might be true with BMP but not with CMP. As you know this is the infamous n+1 selects problem with entity ejbs. However containers might overcome this problem using vendor specific configuration elements. Weblogic for example allows defining a specific tag <finders-load-bean> in weblogic-ejb-jar.xml that could be either true (default) or false. If it is set to true, then weblogic will use only one select to fetch the data.
Regards.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now the question is when to choose between entity home finders and entity home business methods. If the home business methods returning a collection of data are reducing the network traffic, why do you want to use finders, except for findbyprimarykey?



you may need different finders method to return data based on different search criterias which is specified in sql/ejb-ql.

Business method we generally use to separate business logic used to process the data returned by finder method. Different Business logic may be required to apply on the same returned data from a finder method and hence the need for business method. Otherwise you will require to put this business logic in same finder method. But in case of CMP beans this won't be possible because there you just define finder methods and bind ejb-ql with each method. The only processing that can be performed is ejb-ql specific in where etc. clauses which are limited. In BMP beans the business methods processing can be clubbed in finder method but its never a good idea as finder methods are meant to return data which may be required to be processed differently from time to time and hence its a good idea to separate logic from just data retrieval.

finders and business methods are not alernative to each other but rather complimentary and best used in conjuction with each other. If you don't require any further processing on data returned, then you just use finders method.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, I didn't read your 2nd and 3rd points properly.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am talking about HOME business methods!!!(whether CMP or BMP)

I think I will have to give you an example.

consider an entity in the database like person which has firstname, lastname, sex etc... I will create a domain object "Person" with all the setters and getters etc.

I want to get all the males in the database.

1) First solution is to have a findbySex method in the home interface.
This returns a collection of the remote interfaces satisfying that condition. Then the getters say getFirstName, getLastName etc are called on the remote interface. All these calls are remote.

2) Second solution is to have a HOME business method say getPersonsBySex. This will return a collection of Person objects. Now the client can call getters on these any number of times, and these will not be remote.(Although the data is stale. But stale data is better than network overhead!)

I stress again the difference is in HOME business methods and HOME finders methods!!!
 
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


2) Second solution is to have a HOME business method say getPersonsBySex. This will return a collection of Person objects. Now the client can call getters on these any number of times, and these will not be remote.(Although the data is stale. But stale data is better than network overhead!)


There is nothing like home business methods. Home interface defines only life-cycle methods and methods to look up the bean. Hence you cannot define a getPersonsBySex method in the home interface.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I stress again the difference is in HOME business methods and HOME finders methods!!!



I still didn't understood.
 
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
You cannot define business methods in the home interface, is as simple as that. To use your example once more, you cannot define getPersonsBySex() method in the home interface. And I agree with the fact that you cannot understand, because this entire problem is completely nonsense.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr. Valentin!!
You need brush up your EJB2.0 knowledge. Please look into the specs and learn that you can define business methods in the home interface of entity beans. Please think before you say problem is nonsense!
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Mr. Valentin!!
Buy yourself "Head First EJB" and read it 4 to 5 times. Then I hope you will understand the problem(before saying it as nonsense!!)
 
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
Again, accordingly to my knowledge, it is not possible. If RMH says otherwise, I have to assume the ignorance and simply say, he�s wrong; this only because there are other sources that say differently. Unless you won�t be able to prove it through a sample ejb & rmi client, you�re assuming the ignorance of denying the opposite opinions and accept only RMH�s version. However I�m opened to learn new things though. Please write such an ejb and a client app and send me the sources as well as the jars and I promises I�ll install it and check for myself. Also I�ll be very grateful to you for enlighten me in this matter. Till then, you�re talking nonsense.
Regards.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is the excerpt from Final Release of J2EE specs by Sun Microsystems, Inc. I have made the home methods part bold. Mind you this is not my own writing.

10.6.10 Entity bean�s remote home interface

The following are the requirements for the entity bean�s home interface:
The interface must extend the javax.ejb.EJBHome interface.
The methods defined in this interface must follow the rules for RMI-IIOP. This means that their argument and return types must be of valid types for RMI-IIOP, and their throws clauses must include the
java.rmi.RemoteException.
The remote home interface is allowed to have superinterfaces. Use of interface inheritance is subject to
the RMI-IIOP rules for the definition of remote interfaces.
Each method defined in the remote home interface must be one of the following:
� A create method.
� A finder method.
A home method.
Each create method must be named �create<METHOD>�, e.g. createLargeAccounts. Each
create method name must match one of the ejbCreate<METHOD> methods defined in the enterprise
bean class. The matching ejbCreate<METHOD> method must have the same number and types of its
arguments. (Note that the return type is different.)
The return type for a create<METHOD> method must be the entity bean�s remote interface type.
All the exceptions defined in the throws clause of the matching ejbCreate<METHOD> and ejb-
PostCreate<METHOD> methods of the enterprise Bean class must be included in the throws clause
of the matching create method of the home interface (i.e., the set of exceptions defined for the create
method must be a superset of the union of exceptions defined for the ejbCreate<METHOD> and
ejbPostCreate<METHOD> methods).
The throws clause of a create<METHOD> method must include the javax.ejb.CreateException.
Each finder method must be named �find<METHOD>� (e.g. findLargeAccounts).
The return type for a find<METHOD> method must be the entity bean�s remote interface type (for a
single-object finder), or a collection thereof (for a multi-object finder).
The remote home interface must always include the findByPrimaryKey method, which is always a
single-object finder. The method must declare the primary key class as the method argument.
The throws clause of a finder method must include the javax.ejb.FinderException.
Home methods can have arbitrary names, but they must not start with �create�, �find�, or
�remove�. Their argument and return types must be of valid types for RMI-IIOP, and their throws
clauses must include the java.rmi.RemoteException. The matching ejbHome method speci-
fied in the entity bean class must have the same number and types of arguments and must return the
same type as the home method as specified in the remote home interface of the bean.

The remote home interface methods must not expose local interface types, local home interface types,
or the managed collection classes that are used for entity beans with container-managed persistence as
arguments or results.

Even after reading this if you are saying that I am talking nonsense, well! all I can say is "Only ignorant persons say others are ignorant".
Moreover I just don't feel the need to give you sample code(which I have written and tried successfully), I don't see a person willing to learn but just to fight.

Also moderator, could you please close this topic, :roll: I posted this in SCBCD forum and got a better answer from people, who understood the problem in one posting!!!
 
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 have to disagree with you again and to ask the moderator not to close this topic, because in my opinion it�s very interesting. However I have to agree with you this time and thank you for your very valid question, which I failed to appreciate. If other people have the doubts I had I can recommend them a very simple reading that could help them to understand the validity and importance of this topic.
http://www.caucho.com/resin-3.0/ejb/tutorial/ejb-entity-home/index.xtp
Please accept my apologies.
Regards.
 
Sreenath Madasu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally! you got my point! I am so relieved !!!

apologies duly accepted. Lets forget enimity and

Also that was a nice link you gave there.

Thanks
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sreenath & Valentin

Though it was a hot discussion, It has added great knowledge atleast for me . But still i've a question which remained unanswered. could you explain if we can define Business methods in Home interface, then why we need Remote interface. Because instead of Selector method we can use finder methods also. So why we need remote inteface ?

Thanks in Advance
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic