Finder methods are quite simple once you understand what they are used
for.  You use finder methods to "find" (sorry, don't want it to sound
patronising) existing entities.  These enitities have probably already
been created in the past and their data is already stored in the
database.

You are right that you could call the method anything however there is a
naming convention starting finder methods with "findBy".  This naming is
more important for CMP.

In the example below you are calling a create() method on the home
interface.  This is actually creating a brand new entity and new data
for it in the database.  You couldn't use a finder method to get this
entity as it doesn't exist yet.

- create: creates a new entity
- finder: finder an existing one

Hope this helps,

  Tony K. Lawrence.

-----Original Message-----
From: A mailing list for Enterprise JavaBeans development
[mailto:[EMAIL PROTECTED]] On Behalf Of Guess
Sent: 26 June 2001 10:31
To: [EMAIL PROTECTED]
Subject: Re: necessary to get primary key from entitycontext? (part 2)


Thank you for your reply. That clarified it alot.
Another question -- what's the advantage of using a finder method (in a
Bean Managed Persistence Entity Class) to return data instead of
returning it from a method in myEJB class (e.g., getData() function)?

A reference that I have tells me that clients must be able to find the
bean for which they are looking for, and this is why a finder method is
used. In contrary to a session bean where a client gets access to a bean
when it's created. But I'm kind of confused by this. Does this mean that
a client won't have access to a BMP bean until a finder method is
called? There's an example in this book where a client calls a function
on a BMP bean without ever calling a finder method:

SportTeam team = home.create("arg1", "arg2", "arg3", "arg4");
System.out.println(team.getFranchisePlayer());

The above could have been implemented with a finder method?

And there is another:

Collection collection = home.findByOwnernName("Joe");

Could the above be implemented with something other than a finder
method?

Thank you in advance for any help. I just started getting into EJB a few
days ago.

----- Original Message -----
From: "Evan Ireland" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 26, 2001 12:38 AM
Subject: Re: necessary to get primary key from entitycontext? (part 2)


> If you create your bean, and the instance is deactivated, then you
> call a business method and the container selects another instance from

> the instance pool the primary key will not be valid unless you re-set
> it in ejbActivate (or in ejbLoad but doing it in ejbActivate might be
> a little more efficient).
>

========================================================================
===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body of the message "signoff EJB-INTEREST".  For general help, send
email to [EMAIL PROTECTED] and include in the body of the message
"help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to