I personally do exactly this.
If you image the finder method actually doing a database lookup then you will be
doing the following:
ejbFindByPrimaryKey() - does database lookup (SELECT)
if Entity Bean not loaded into server then
create new EJB inmemory and populate using ejbLoad - (SELECT)
So in this case you have done 2 database lookups which i think is much more
expensive. The EJB clinet will still get the FinderException whichever way you
do it so I always go with the finder simply returning the PK without doing a
lookup.
In fact I would go one step further - if ever I have a finder method (primary
key or not) where I can get / calculate the primary key withough doing a
database lookup I will (e.g. composite key etc).
davep
>
> Hi,
>
> I just saw a bea slide which recommends to implement ejbFindByPrimaryKey by
> just returning the parameter:
>
> String ejbFindByPrimaryKey(String pk)
> {
> return pk;
> }
>
> This code does not perfom a database lookup.
>
> The above coding has consequences:
> 1. if a bean with the specified pk does not exist, ejbFindByPrimaryKey will
> not throw a FinderException. Instead, ejbLoad will fail (in which case a
> FinderException can be thrown).
> 2. No database lock is set to the tuple with the pk.
>
> Has someone out there experiences with the optimized code?
>
> Thanks,
> Marc Volz
> TLC, Germany
>
> ===========================================================================
> 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".
>
----------------------------------
Dave Pinnington - Sun Microsystems
[EMAIL PROTECTED]
tel: +44 (0)1223 418868
fax: +44 (0)1223 420257
===========================================================================
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".
Re: ejbFindByPrimaryKey & Database lookup
David Pinnington - Sun UK - Consultant Thu, 25 May 2000 01:41:25 -0700
- ejbFindByPrimaryKey & Database ... Marc . Volz
- Re: ejbFindByPrimaryKey & ... Rob Woollen
- Re: ejbFindByPrimaryKey & ... David Pinnington - Sun UK - Consultant
- Re: ejbFindByPrimaryKey &a... Richard Monson-Haefel
- Re: ejbFindByPrimaryKe... Victor Langelo
- Re: ejbFindByPrima... Jean-Baptiste Nizet
- Re: ejbFindByPrimaryKe... Robert Nicholson
- Re: ejbFindByPrimaryKey &a... Robert Nicholson
- Re: ejbFindByPrimaryKey &a... Robert Nicholson
- Re: ejbFindByPrimaryKey & ... Bhattacharyya, Ana
- Re: ejbFindByPrimaryKey &a... Evan Ireland
- Re: ejbFindByPrimaryKe... Shiv Kumar
