Isn't this more overhead (A view on the DB for each sequence, lots of CMP
Entity beans floating around) vs in the ejbCreate, grabbing a connection
from the connection pool, and getting a sequence?


Chip Whiteside
Senior Software Engineer
ADASTAR, LLC
-----Original Message-----
From: Scot Cunningham [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 26, 2000 8:33 AM
To: [EMAIL PROTECTED]
Subject: Re: Entity beans and sequence


I didn't want the EJB client to have to obtain the
nextval from the sequence either.
My approach to this was to create a session bean with
a method that obtains the nextval from the sequence
(there are a couple approaches to that part) and use
that value for the create() on the entity bean.  The
client calls the session bean for the create and the
complete entity bean (with the new ID) is returned.

To obtain the sequence, I created a read-only CMP
entity bean that accessed a view defined as follows:
        create view seq as (select guid.nextval from dual);
I created a custom finder on that entity bean to
select nextval from seq.
I could have taken a more direct JDBC approach, but I was
seeing if I could keep it pure CMP.

[Charset iso-8859-1 unsupported, filtering to ASCII...]
> I was thinking that even as I typed it :-(
> Then, I guess the only way to go is to use the query :
> "select sequence.nextval from dual". and use the value from the result to
> set the primary key.  This is definitely a two step process, if you need
the
> value of the primary key after the insert. It would be even directly in
> PL/SQL.
> -----Original Message-----
> From: Louth, William (Exchange) [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 26, 2000 7:03 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Entity beans and sequence
>
>
> Hi Mark,
>
> I think the problem with your approach is that Shiv's entity bean will
need
> to know the value of the id (primary key) obtained from the sequence.
>
> kind regards,
>
> William Louth
>
> > -----Original Message-----
> > From: Mark Zawadzki [SMTP:[EMAIL PROTECTED]]
> > Sent: Wednesday, April 26, 2000 11:50 AM
> > To:   [EMAIL PROTECTED]
> > Subject:      Re: Entity beans and sequence
> >
> > Since you are using Oracle, you can use a pre-insert trigger (see the
> > Oracle
> > docs), then
> > it will not matter what the id is going in.
> >
> > -----Original Message-----
> > From: Shiv Kumar [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, April 26, 2000 2:49 AM
> > To: [EMAIL PROTECTED]
> > Subject: Entity beans and sequence
> >
> >
> > Hi all
> >
> > I have an entity bean which maps to a table with three columns :-
> >
> >      id integer PK
> >      name varchar not null
> >      description varchar
> >
> > I have also created a sequence (myseq) in Oracle which will give the
next
> > number
> > in the sequence (myseq.nextval). Whenever the ejbCreate() method is
> > called,
> > I
> > want the following query to be generated:
> >
> >      insert into t1 values (myseq.nextval, name, description)
> >
> > where 'name' and 'description' will be passed as parameters to
ejbCreate()
> > method. I specifically dont want clients to pass the id (PK) as a
> > parameter
> > because I can always use the sequence to generate the next number. And I
> > want my
> > bean to use CMP.
> >
> > How do I achieve this?
> >
> > Thanks
> > --
> > shiv
> > [EMAIL PROTECTED]
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Talk to your friends online with Yahoo! Messenger.
> > http://im.yahoo.com
> >
> >
==========================================================================
> > =
> > 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".
>
>
> ***********************************************************************
> Bear Stearns is not responsible for any recommendation, solicitation,
> offer or agreement or any information about any transaction, customer
> account or account activity contained in this communication.
> ***********************************************************************
>
>
===========================================================================
> 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".
>
>

===========================================================================
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