• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

EJB QL: Difference between find and select methods

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
What is the difference between find and select methods in EJB QL? I know one. Select methods cannot be exposed to the client of the bean. can anybody tell me , why this is so? why the select methods are private to bean? Why can't the client use select method? In addition, where do u declare the ejbselect method? as u cannot expose it thr' home interface, do u declare it as a private method in home interface?
In addition , what are other differences between find and select?
Thanks in advance.
-Rashmi
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You make an entry for the select methods in the ejb-jar.xml. The ejbSelect methods must be public and not private. The ejbSelect methods exceutes in a Tx context of the calling method.
Also, Select methods can return the values of CMP fields.
 
Saloon Keeper
Posts: 3947
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you can expose your "ejbSelect" methods results to the client using "ejbHome" methods.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashmi,
One more difference is that ejbSelect<*>() methods are defined in your bean class as abstract methods (remember that CMP entity beans classes must be abstract), while ejbFind<*>() methods are not defined in your bean class at all. The container has to write your concrete bean class anyway, as you provide it as an abstract one. For find methods, it has enough information with the DD (the <query> elements) *and* your home interface (where find methods are exposed to the client), to "guess" which code it has to write. It's different for select methods because they are *not* exposed to the client. So it uses your abstract ejbSelect<*>() definitions as a model to write the concrete methods. Select methods are not exposed to the client because they are ... reserved for your personal use as a bean provider (ejbSelect<*>() == selfish ) . Each time you'll be writing some business method of a CMP entity bean, there are many chances you'll need to access your DB through some SQL SELECT statement(s). With CMP beans, your have no other choice than to define an abstract ejbSelect<*>() method and write a corresponding EJB-QL query in the DD. If you need the client a *direct* access to such a SELECT statement, you have to write a home find<*>() method instead.
Best,
Phil.
[ December 09, 2003: Message edited by: Philippe Maquet ]
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks all!
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good question...one more difference....
ejbFind methods are executed by beans in a pooled state, while ejbSelect methods are executed by beans either in a pooled state or ready state.
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ejbFind methods are executed by beans in a pooled state, while ejbSelect methods are executed by beans either in a pooled state or ready state.


It is a must condition for ejbFind methods to be executed by beans in a pooled state? So does this mean that a bean in ready state wont ever execute ejbFind? Why this is not applied to ejbSelect? i am not sure abt this...i mean, is it detected by ejb specs?
Can u explain more...
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why this is not applied to ejbSelect?


That is whole point of not having it exposed to the client. The ejbSelect methods can be called by any business/ ejbHome method.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rashmi Tambe:

It is a must condition for ejbFind methods to be executed by beans in a pooled state? So does this mean that a bean in ready state wont ever execute ejbFind? Why this is not applied to ejbSelect? i am not sure abt this...i mean, is it detected by ejb specs?
Can u explain more...


Please refer : EJB Specs 10.5.1 - Instance Life cycle.(p:168-169)
There is a good diagram showing, the methods of an entity bean and the states in which they are executed...and also the explanation in the below 3 paragraphs...
As pradeep said, if the ejbSelect methods are called from the home business methods, then they are executed by beans in the pooled state but if they are called from remote business methods, then they are executed by beans in the ready state...
Even though the spec uses the friendly ambiguous words "may" and "can", I think that the ejbFind methods and the ejbHome business methods are executed by the beans only in the pooled state.
Say for example: if there are 2 entity beans in the pooled state, A and B.
If I call a finder() method for the first time, bean instance A may be used to execute my ejbFinder() method. Then say, I call a remote business method, then also the container may choose the bean instance A, move it to the Ready State and execute the business method. Now if I call another finder method on the same home interface, then I think it might be the instance B in the Pooled state which will be selected for the ejbFinder method execution and not instance A, which is already in the Ready state.
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot vish, for a very good explaination !
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finder and select methods use EJB QL queries to return objects and state information of entity beans using container-managed persistence.

A select method is similar to a finder method in the following ways:

1. A select method can return a local or remote interface (or a collection of interfaces).
2. A select method queries a database.
3. The deployment descriptor specifies an EJB QL query for a select method.
4. The entity bean class does not implement the select method.

However, a select method differs significantly from a finder method:

1. A select method can return a persistent field (or a collection thereof) of a related entity bean. A finder method can return only a local or remote interface (or a collection of interfaces).
2. Because it is not exposed in any of the local or remote interfaces, a select method cannot be invoked by a client. It can be invoked only by the methods implemented within the entity bean class. A select method is usually invoked by either a business or a home method.
3. A select method is defined in the entity bean class. For bean-managed persistence, a finder method is defined in the entity bean class, but for container-managed persistence it is not.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic