[JBoss-user] EJB question

2001-07-05 Thread Hermann RANGAMANA

Hi all,

In my session bean, i have reference to an instance of an entity bean. so, i
lookup an instance of the home interface of the entity bean using the bean
name or  jndi name. The problem is that, with this approach, i have to
hardcode the entity bean name or its jndi name within the session bean
wich is, IMO, not a very good approach  : if the referenced entity bean is
deployed with a different name, the session bean directly crashes 

Any suggestions to avoid this? Does the spec provide some way for the
session bean to know the deployed name of an entity bean it's referencing
to?

--hermann


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-07-05 Thread Alex . Devine


You should declare a reference to the entity bean in the deployment
descriptor, like this:


session
...
  ejb-ref
ejb-ref-nameejb/LogEventInfo/ejb-ref-name
ejb-ref-typeEntity/ejb-ref-type
homecom.trilogy.tbs.logging.LogEventInfoHome/home
remotecom.trilogy.tbs.logging.LogEventInfo/remote
ejb-linkLogEventInfo/ejb-link
  /ejb-ref
/session

This way, you will code your session bean so that it always does a lookup
like:

jndiCtx.lookup(java:comp/env/ejb/LogEventInfo);

This way, if the entity bean is ever deployed with a different name, all
you have to do is change the ejb-link tag to point to the new name.

Alex


|+--
||  Hermann RANGAMANA |
||  [EMAIL PROTECTED] |
||  Sent by:|
||  [EMAIL PROTECTED]|
||  eforge.net  |
||  |
||  |
||  07/05/01 07:36 AM   |
||  Please respond to jboss-user|
||  |
|+--
  
---|
  |
   |
  |   To: [EMAIL PROTECTED]   
   |
  |   cc:  
   |
  |   Subject: [JBoss-user] EJB question   
   |
  
---|




Hi all,

In my session bean, i have reference to an instance of an entity bean. so,
i
lookup an instance of the home interface of the entity bean using the bean
name or  jndi name. The problem is that, with this approach, i have to
hardcode the entity bean name or its jndi name within the session bean
wich is, IMO, not a very good approach  : if the referenced entity bean is
deployed with a different name, the session bean directly crashes 

Any suggestions to avoid this? Does the spec provide some way for the
session bean to know the deployed name of an entity bean it's referencing
to?

--hermann


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user





___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-07-05 Thread Alex . Devine


Yes, the ejb-link tag is the ejb-name of the referenced bean (as specified
in another section of the deployment descriptor). The ejb-ref-name is the
jndi name, relative to java:comp/env. Thus, perhaps a better example would
have been:

ejb-ref-nameejb/WhateverIWant/ejb-ref-name
...
ejb-linkOtherEJBName/ejb-link


and then in the code
jndiCtx.lookup(java:comp/env/ejb/WhateverIWant)
will return the home interface of the bean named OtherEJBName.

Also note that the ejb/ prefix in the ejb-ref-name is not required, just
suggested by the spec.



|+--
||  danch (Dan Christopherson)|
||  [EMAIL PROTECTED]  |
||  Sent by:|
||  [EMAIL PROTECTED]|
||  eforge.net  |
||  |
||  |
||  07/05/01 02:23 PM   |
||  Please respond to jboss-user|
||  |
|+--
  
---|
  |
   |
  |   To: [EMAIL PROTECTED] 
   |
  |   cc:  
   |
  |   Subject: Re: [JBoss-user] EJB question   
   |
  
---|




I believe the ejb-link tag is the ejb-name, not necessarily the
jndi-name for the bean.

[EMAIL PROTECTED] wrote:

 You should declare a reference to the entity bean in the deployment
 descriptor, like this:


 session
 ...
   ejb-ref
 ejb-ref-nameejb/LogEventInfo/ejb-ref-name
 ejb-ref-typeEntity/ejb-ref-type
 homecom.trilogy.tbs.logging.LogEventInfoHome/home
 remotecom.trilogy.tbs.logging.LogEventInfo/remote
 ejb-linkLogEventInfo/ejb-link
   /ejb-ref
 /session

 This way, you will code your session bean so that it always does a lookup
 like:

 jndiCtx.lookup(java:comp/env/ejb/LogEventInfo);

 This way, if the entity bean is ever deployed with a different name, all
 you have to do is change the ejb-link tag to point to the new name.

 Alex



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user





___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-09 Thread Jim Archer



--On Tuesday, May 08, 2001 11:17 AM +0800 Ralph Jensen [EMAIL PROTECTED] 
wrote:

 As danch said: ejbCreate needs to know it, because it must return it,
 according to spec. What actually happens, if it doesn't?

Beats me... In EJB 2.0, we return null, although I think that changed in 
the latest PFD. So I have never tried it.

 I was thinking of a function like sendContribution( Object content,
 clientID, somethingElse ); or possibly two: sendText( String text,
 clientID, ... ) and sendBinary( Object content, clientID, ... ) if I want
 to have different tables for text and non-text contributions.
 The question now is, where these methods should be located. If I
 understand you correctly, you say that's a session bean.

Yes, its become accepted that session beans are generally used to create 
entity beans and manipulate them and otherwise hole business logic. Of 
course, there is nothing that stops you from using JDBC to access a 
database from a session bean if thats the best sollution for your app.

 Somebody has to create a conference. That is done by entering a record
 into a database, with fields like topic, starttime, endtime and other
 configurable items, plus a 'status' column that tells if the conference is
 in process or not. The collaborative session is then that one record
 represented by one entity bean.

OK, I see.

 So you mean, the contribution methods would go into a session bean?
 The session bean would check, if the conference is in process by accessing
 above ConferenceBean, (then check some other stuff accessing some other
 beans ...) and THEN: write the contribution into a table without using an
 entity bean in order to circumvent the primary key issue, which started
 this discussion. Meaning, if I use and ejbCreate(...) method that
 ejbCreate needs to return the primary key, but I want the database to
 asign it and there is no portable way to get it into the bean.

This would work. But I would recomend using BMP and dealing with the 
primary key/sequence issue in the entity bean.

 I was thinking of two contribution types because a participant can send
 either text or non-text. Having one contribution type seems to indicate
 that I each record needs to have columns for text and BLOBs while at any
 time only one will be used.

Makes good sense. As I think about it, I guess all the types of 
contributions can probably be either binary data or textual data.

 So, your session bean would be handed the user id of the contributor and
 the contribution and told to make a new EB to represent the contribution.

 To make a new EJB representing the contribution created the problem in the
 first place. I would have to call ContributionHome.create(...) or so,
 which requires and ejbCreate(...), which needs to return the primary key.
 So I want to INSERT the contribution without using a bean. If I later
 need to list contributions I would of course use EJBs with custom finder
 methods.

As we decided above, this would work, but my personal opinion is that two 
better options are 1) use an EB that uses BMP, or 2) use a unique key 
generator and not the database sequence type. But reasonable people can 
certianally disagree.

 I will use BMP for now.

A good choice.

 Right, but again, for the purpose of creating the data I'd like to do it
 without an ejbCreate(...). Handling existing data would be done with
 beans.

Yup, that will work.

 Why would I be tied to a database? All I need is that the database
 supports something like the autoincrement feature. I don't want to read
 the key back at creation time, and later I use custom finders with other
 fields. I just want to avoid the overhead from using multiple fields for
 the primary key (which is probably impossible anyway due to the nature of
 the data) or from creating a unique key, when the database can do it best.

Well, I have worked mostly with PostgreSQL, MS SQL Server and Oracle. As I 
recall, all three had a different way of getting the value of the created 
serial field. But, as you say, your not interesting in reading that data 
back. I guess as long as your carefull with the BMP SQL, you'll not be tied 
to a database.

Best of luck!

Jim





___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-09 Thread Ralph Jensen

For all that it's worth - I certainly appreciate this jBoss unrelated
discussion and the help I received. There is a lot of expertise bundled in
this newsgroup.

Does anybody know of groups where these kind of discussions are on topic?
I've tried the SUN discussion forums but that wasn't exciting.

Ralph

- Original Message -
From: Jim Archer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, May 10, 2001 3:57 AM
Subject: Re: [JBoss-user] EJB question





 Best of luck!

 Jim

 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] EJB question

2001-05-07 Thread Jim Archer

Hal, were you able to find the actual source for this? I searched and 
searched last week with no luck...

Jim

--On Friday, May 04, 2001 8:33 AM -0400 Deadman, Hal 
[EMAIL PROTECTED] wrote:

 Take a look at the key generator that comes with Exolab's Castor
 (open-source). http://castor.exolab.org/key-generator.html

 You probably want something like their HIGH/LOW generator. I haven't used
 it but I use a similiar technique that I wrote myself. I like their
 implementation better because they let you use different key gen
 techniques that you can specify in the config file without changing code.
 They offer a max+1 option which you should stay away from b/c I don't see
 how that could guarantee uniqueness.

 The castor high/low generator uses a database but it grabs a range of
 values with each db hit so you don't hit the db everytime.

 Hal

 -Original Message-
 From: Ralph Jensen [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 04, 2001 7:27 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [JBoss-user] EJB question


 Thanks. But that is actually much more than I want. I only
 need a unique
 INT for primary keys.

 For the moment I will try this:

 In the sql-script:

 create table uniqueInteger(
 pk INTEGER constraint pk_unique primary key,
 uniqueID INTEGER
 );

 insert into uniqueInteger VALUES( 1, 1 );


 Then in the bean:
 SELECT uniqueID from uniqeInteger;

 save uniqueID in variable ( let's call it 'uniqueVar' )

 then:

 UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;


 I think that's basically Vinay's suggestion. Does that look
 reasonable?
 That's a lot of database access to get a unique primary key,
 just to be
 able to return it from ejbCreate() - especially in light of
 the fact, that
 databases do it automatically, if the table is created
 accordingly. Isn't
 this kind of thing done regularly?


 I know this has nothing to do with jBoss. Thank you.  :-)

 Ralph

 - Original Message -
 From: Jim Downing [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, May 04, 2001 5:47 PM
 Subject: Re: [JBoss-user] EJB question


  Check out www.activescript.co.uk for a non-free ($99) component to
 generate
  unique ids. The author has also posted the pattern on
 theserverside.com,
 so
  you have something to work to if you want to implement it yourself.
 
  jim
 
  - Original Message -
  From: Ralph Jensen [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, May 04, 2001 10:25 AM
  Subject: Re: [JBoss-user] EJB question
 
 
   The portability would be there in terms of data access.
 How to tell the
   database to autoincrement when I create a table is probably always
  database
   specific. Or not?
  
   I'm not good at SQL. So how would your suggestion look in
 code? What
 would
   the key generator bean look like? Off which table would it work?
  
   Ralph
  
   - Original Message -
   From: Vinay Menon [EMAIL PROTECTED]
   To: JBOSS [EMAIL PROTECTED]
   Sent: Friday, May 04, 2001 4:29 PM
   Subject: Re: [JBoss-user] EJB question
  
  
   Why don't you just use a primary key generator bean to
 encapsulate the
 key
   genaration? The ejbCreate can then work off that ejb and
 assign the
  primary
   key field to the primary key generated field? so your
 autoincrement
   essentially will not be on the same table as the ejb but
 a different
 one
   and the primary key generator will work off that table.
 [Also makes
 sure
   that you have complete protability in terms of the
 database server!]
  
   Vinay
  
  
  
   - Original Message -
   From: Ralph Jensen
   Sent: Friday, May 04, 2001 8:52 AM
   To: [EMAIL PROTECTED]
   Subject: [JBoss-user] EJB question
  
  
   I asked this question elsewhere, but didn't get an answer. So:
  
   An entity bean's ejbCreate(...) method MUST return the
 primary key.
 That
  is
   not a problem, if I specify the primary key myself and
 pass it to the
   create(...) method.
  
   But I want to let the database assign the primary key by
 creating a
 table
   with an AUTOINCREMENT default for the primary key column,
 like in this
   example using Cloudscape (part of SUN's J2EE v1.3):
  
   create table myTable(
  id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
  someString VARCHAR(6),
  etc.
   );
  
   Then I can use INSERT like this:
  INSERT INTO mytable ( someString ) VALUES ( 'Hello' );
  
   The database then assigns a unique value to the id column
 of that new
   record.
  
   If I do this in the ejbCreate(...) method of my bean my
 problem is: How
 do
   I know that value in order to return it? Is that possible?
  
   Thanks
  
   Ralph Jensen
  
  
   ___
   JBoss-user mailing list
   [EMAIL PROTECTED]
   http://lists.sourceforge.net/lists/listinfo/jboss-userbr
  clear=allhrGet
   your FREE download of MSN Explorer at a
   href=http://explorer.msn.com;http://explorer.msn.com/abr/p

Re: [JBoss-user] EJB question

2001-05-07 Thread Ralph Jensen


- Original Message -
From: Jim Archer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, May 07, 2001 3:28 PM
Subject: Re: [JBoss-user] EJB question


 Or, if you want a sollution thats free and lots easier, look at your java
 SDK docs at java.rmi.server.UID class.

 One of the major critisims of EJB as it currently exists is that it can't
 take advantage of a databases serial or autoincrement field. Of
course,
 these all vary from database to database anyhow, and EJB is not even tied
 to a relational database.

That probably means that java.sql can't do it. Even if it could, that
wouldn't solve the problem with non-relational databases.

 So using a primary key generator is a necessity if you can't create your
PK
 from your data (maybe by combining other fields).

 Good luck!
 Jim


Actually, the original question came up in this context:

I am developing a collaborative application which stores the contributions
of participants in a database. These contributions could be text messages
or other objects, stored as blobs. None of the individual elements will be
useful as a primary key and thus I thought, why not let the database create
a unique key. My original question arose from the fact that an EJB needs to
know the primary key in order to return it and my assumption that I have to
call create(...) on an EJB in order to insert new data.

But I could also do it this way:

I have an EJB which represents one collaborative session - let's call it a
Conference. It represents a record in a table called conferenceTable. In
creation of this conference, all the issues discussed concerning uniqueness
of keys are relevant. But because I create that only once I may even
trouble the creator to enter a unique conference id. (Don't we all know it:
Your userid isnt unique. Try again. Suggestion: 'mk$rtio237k'. :-). Then,
during the session, participants will add a lot of information and that's
where I want to minimize the effort for creating unique keys.

I can add methods to my Conference bean like Conference.sendText( text,
client ) or Conference.sendOtherStuff( blob, client ) and then within these
methods do INSERTs into another table which hold the contributions of
participants, somehow like this:

Conference.sendText( text, client ){
   ...
   t_stamp = System.currentTimeMillis();
   INSERT INTO contributions( confID, text, client, timestamp ) VALUES
 conferenceID, text, client, t_stamp );
   ...
}


That means my ConferenceBean - which represents a record from the
conferenceTable - INSERTs data into another table.


That table could be created with an AUTOINCREMENT (or similar, depending on
the database) for the primary key and thus primary keys are generated
transparently by the database during the INSERT. But I don't need to know
it, because the INSERT is not performed in an ejbCreate() method and
doesn't need to be returned.

(In reality I will probably write a second EJB, which participants can use
but which does not allow access to all fields of the Conference record.)

Does that sound reasonable or am I in for trouble somewhere else?

Ralph


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] EJB question

2001-05-07 Thread Deadman, Hal

It looks like the code is in this distribution:
ftp://ftp.exolab.org/pub/castor/castor_0.9.2/castor-0.9.2-src.zip
from this page http://castor.exolab.org/download.html

Look for *KeyGen*.java. I haven't had a chance to try to use it and I don't
know if you can use it with CMP entity beans.

Hal

 -Original Message-
 From: Jim Archer [mailto:[EMAIL PROTECTED]]
 Sent: Monday, May 07, 2001 3:30 AM
 To: [EMAIL PROTECTED]
 Subject: RE: [JBoss-user] EJB question


 Hal, were you able to find the actual source for this? I searched and
 searched last week with no luck...

 Jim

 --On Friday, May 04, 2001 8:33 AM -0400 Deadman, Hal
 [EMAIL PROTECTED] wrote:

  Take a look at the key generator that comes with Exolab's Castor
  (open-source). http://castor.exolab.org/key-generator.html
 
  You probably want something like their HIGH/LOW generator.
 I haven't used
  it but I use a similiar technique that I wrote myself. I like their
  implementation better because they let you use different key gen
  techniques that you can specify in the config file without
 changing code.
  They offer a max+1 option which you should stay away from
 b/c I don't see
  how that could guarantee uniqueness.
 
  The castor high/low generator uses a database but it grabs
 a range of
  values with each db hit so you don't hit the db everytime.
 
  Hal
 
  -Original Message-
  From: Ralph Jensen [mailto:[EMAIL PROTECTED]]
  Sent: Friday, May 04, 2001 7:27 AM
  To: [EMAIL PROTECTED]
  Subject: Re: [JBoss-user] EJB question
 
 
  Thanks. But that is actually much more than I want. I only
  need a unique
  INT for primary keys.
 
  For the moment I will try this:
 
  In the sql-script:
 
  create table uniqueInteger(
  pk INTEGER constraint pk_unique primary key,
  uniqueID INTEGER
  );
 
  insert into uniqueInteger VALUES( 1, 1 );
 
 
  Then in the bean:
  SELECT uniqueID from uniqeInteger;
 
  save uniqueID in variable ( let's call it 'uniqueVar' )
 
  then:
 
  UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;
 
 
  I think that's basically Vinay's suggestion. Does that look
  reasonable?
  That's a lot of database access to get a unique primary key,
  just to be
  able to return it from ejbCreate() - especially in light of
  the fact, that
  databases do it automatically, if the table is created
  accordingly. Isn't
  this kind of thing done regularly?
 
 
  I know this has nothing to do with jBoss. Thank you.  :-)
 
  Ralph
 
  - Original Message -
  From: Jim Downing [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, May 04, 2001 5:47 PM
  Subject: Re: [JBoss-user] EJB question
 
 
   Check out www.activescript.co.uk for a non-free ($99)
 component to
  generate
   unique ids. The author has also posted the pattern on
  theserverside.com,
  so
   you have something to work to if you want to implement
 it yourself.
  
   jim
  
   - Original Message -
   From: Ralph Jensen [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   Sent: Friday, May 04, 2001 10:25 AM
   Subject: Re: [JBoss-user] EJB question
  
  
The portability would be there in terms of data access.
  How to tell the
database to autoincrement when I create a table is
 probably always
   database
specific. Or not?
   
I'm not good at SQL. So how would your suggestion look in
  code? What
  would
the key generator bean look like? Off which table
 would it work?
   
Ralph
   
- Original Message -
From: Vinay Menon [EMAIL PROTECTED]
To: JBOSS [EMAIL PROTECTED]
Sent: Friday, May 04, 2001 4:29 PM
Subject: Re: [JBoss-user] EJB question
   
   
Why don't you just use a primary key generator bean to
  encapsulate the
  key
genaration? The ejbCreate can then work off that ejb and
  assign the
   primary
key field to the primary key generated field? so your
  autoincrement
essentially will not be on the same table as the ejb but
  a different
  one
and the primary key generator will work off that table.
  [Also makes
  sure
that you have complete protability in terms of the
  database server!]
   
Vinay
   
   
   
- Original Message -
From: Ralph Jensen
Sent: Friday, May 04, 2001 8:52 AM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] EJB question
   
   
I asked this question elsewhere, but didn't get an answer. So:
   
An entity bean's ejbCreate(...) method MUST return the
  primary key.
  That
   is
not a problem, if I specify the primary key myself and
  pass it to the
create(...) method.
   
But I want to let the database assign the primary key by
  creating a
  table
with an AUTOINCREMENT default for the primary key column,
  like in this
example using Cloudscape (part of SUN's J2EE v1.3):
   
create table myTable(
   id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
   someString VARCHAR(6),
   etc.
);
   
Then I can use INSERT like this:
   INSERT INTO mytable

Re: [JBoss-user] EJB question

2001-05-07 Thread Jim Archer

Hi Ralph...

--On Monday, May 07, 2001 4:36 PM +0800 Ralph Jensen [EMAIL PROTECTED] 
wrote:

 That probably means that java.sql can't do it. Even if it could, that
 wouldn't solve the problem with non-relational databases.


Right.


 Actually, the original question came up in this context:

 I am developing a collaborative application which stores the contributions
 of participants in a database. These contributions could be text messages
 or other objects, stored as blobs. None of the individual elements will be
 useful as a primary key and thus I thought, why not let the database
 create a unique key. My original question arose from the fact that an EJB
 needs to know the primary key in order to return it and my assumption
 that I have to call create(...) on an EJB in order to insert new data.

I'm not sure what you mean by the EJB needs to know the primark key to 
return it... All your entity beans need to have a primary key, but your 
home interface can have finder methods that don't need the primary key. If 
you have different people making contributions, then you are probably (my 
poor assumption) going to need a way to tell who made what? So you can 
search by the username field or something like that to get vack a 
COllection of all the entity beans that have that username.

You can do this with ny field, of course, although I'm not exactly sure how 
it would work with a BLOB.

 But I could also do it this way:

 I have an EJB which represents one collaborative session - let's call it a

I'm not sure what a collaborative session is - one record or many? I think 
you mean it would be a bunch of entity beans...

 Conference. It represents a record in a table called conferenceTable. In
 creation of this conference, all the issues discussed concerning
 uniqueness of keys are relevant. But because I create that only once I
 may even trouble the creator to enter a unique conference id. (Don't we
 all know it: Your userid isnt unique. Try again. Suggestion:
 'mk$rtio237k'. :-). Then, during the session, participants will add a
 lot of information and that's where I want to minimize the effort for
 creating unique keys.

 I can add methods to my Conference bean like Conference.sendText( text,
 client ) or Conference.sendOtherStuff( blob, client ) and then within
 these methods do INSERTs into another table which hold the contributions
 of participants, somehow like this:

First, the issue of an API for the other code. Generally, a good EJB design 
will use a session bean to access entity beans. Your busines logic would go 
into the session bean, so methods that create new data, manipulate existing 
data and so on would go here. This presents a nice API to the rest of the 
code that you can change the implementation of.

So the session bean might have a method like sendText(text, client)

Now, the issue of the data and how its related. It seems like you are 
talking about having two entity beans. One to represent the person (or 
client?) making the contribution. This EB might have fields to identify 
that person. Next, you have an EB to represent the contribution. This EB 
might have a field to home the contribution, like a BLOB field. It would be 
easy if you hade only one contributiun type, but if you have multiple types 
(text, binary) you may want to look at multiple EBs for each type.

So, your session bean would be handed the user id of the contributor and 
the contribution and told to make a new EB to represent the contribution. 
You would then find the EB for the contributor, get its remote inteface 
(using a finder from its home object) and give the remote interfce to the 
contribution EB to relate the two.

EJB 1.1 does not handle these things very well if your using CMP, but thats 
being fixed in EJB 2.0.

 That table could be created with an AUTOINCREMENT (or similar, depending
 on the database) for the primary key and thus primary keys are generated
 transparently by the database during the INSERT. But I don't need to know
 it, because the INSERT is not performed in an ejbCreate() method and
 doesn't need to be returned.

Probably, you might want to look at using BMP for this contribution bean. 
Under BMP, you write all the database code with JDBC. When the bean is 
created the create method you wrote is called. You could create the record 
and let your database init the autoincrement field, then read it back. 
Also, you would handle the relationship using the PK rather than a 
serialized remote interface.

But I would not recomend that at all. I would recomend that you use a 
unique key genertor to create your key. If you don't you'll be heavily tied 
to whatever database you write this for. The java.rmi.server.UID class will 
generate a unique key for the machine your using, and you can add the IP 
address for global uniqueness.

If your just starting pout with this, you may want to look at EJB 2.0. The 
spec is not final yet, but its close. EJB 2.0 CMP has vastly improved 
support for 

Re: [JBoss-user] EJB question

2001-05-07 Thread Ralph Jensen


- Original Message -
From: Jim Archer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: Ralph Jensen [EMAIL PROTECTED]
Sent: Tuesday, May 08, 2001 4:03 AM
Subject: Re: [JBoss-user] EJB question


 Hi Ralph...
 ...

  Actually, the original question came up in this context:
 
  I am developing a collaborative application which stores the
contributions
  of participants in a database. These contributions could be text
messages
  or other objects, stored as blobs. None of the individual elements will
be
  useful as a primary key and thus I thought, why not let the database
  create a unique key. My original question arose from the fact that an
EJB
  needs to know the primary key in order to return it and my assumption
  that I have to call create(...) on an EJB in order to insert new data.

 I'm not sure what you mean by the EJB needs to know the primark key to
 return it... All your entity beans need to have a primary key, but your
 home interface can have finder methods that don't need the primary key.

As danch said: ejbCreate needs to know it, because it must return it,
according to spec. What actually happens, if it doesn't?

If
 you have different people making contributions, then you are probably (my
 poor assumption) going to need a way to tell who made what? So you can
 search by the username field or something like that to get vack a
 COllection of all the entity beans that have that username.

I was thinking of a function like sendContribution( Object content,
clientID, somethingElse ); or possibly two: sendText( String text,
clientID, ... ) and sendBinary( Object content, clientID, ... ) if I want
to have different tables for text and non-text contributions.
The question now is, where these methods should be located. If I understand
you correctly, you say that's a session bean.

 You can do this with ny field, of course, although I'm not exactly sure
how
 it would work with a BLOB.

The searching then would have to be done depending on the choice above.


  But I could also do it this way:
 
  I have an EJB which represents one collaborative session - let's call
it a

 I'm not sure what a collaborative session is - one record or many? I
think
 you mean it would be a bunch of entity beans...

Somebody has to create a conference. That is done by entering a record into
a database, with fields like topic, starttime, endtime and other
configurable items, plus a 'status' column that tells if the conference is
in process or not. The collaborative session is then that one record
represented by one entity bean.

  Conference. It represents a record in a table called conferenceTable.

 ...
 
  I can add methods to my Conference bean like Conference.sendText( text,
  client ) or Conference.sendOtherStuff( blob, client ) and then within
  these methods do INSERTs into another table which hold the
contributions
  of participants, somehow like this:

I meant to add the one or two contribution methods to the above entity bean
representing the conference.

 First, the issue of an API for the other code. Generally, a good EJB
design
 will use a session bean to access entity beans. Your busines logic would
go
 into the session bean, so methods that create new data, manipulate
existing
 data and so on would go here. This presents a nice API to the rest of the
 code that you can change the implementation of.

 So the session bean might have a method like sendText(text, client)

So you mean, the contribution methods would go into a session bean?
The session bean would check, if the conference is in process by accessing
above ConferenceBean, (then check some other stuff accessing some other
beans ...) and THEN: write the contribution into a table without using an
entity bean in order to circumvent the primary key issue, which started
this discussion. Meaning, if I use and ejbCreate(...) method that ejbCreate
needs to return the primary key, but I want the database to asign it and
there is no portable way to get it into the bean.

 Now, the issue of the data and how its related. It seems like you are
 talking about having two entity beans. One to represent the person (or
 client?) making the contribution. This EB might have fields to identify
 that person. Next, you have an EB to represent the contribution. This EB
 might have a field to home the contribution, like a BLOB field. It would
be
 easy if you hade only one contributiun type, but if you have multiple
types
 (text, binary) you may want to look at multiple EBs for each type.

I was thinking of two contribution types because a participant can send
either text or non-text. Having one contribution type seems to indicate
that I each record needs to have columns for text and BLOBs while at any
time only one will be used.

 So, your session bean would be handed the user id of the contributor and
 the contribution and told to make a new EB to represent the contribution.
To make a new EJB representing the contribution created the problem in the
first place. I would

[JBoss-user] EJB question

2001-05-04 Thread Ralph Jensen

I asked this question elsewhere, but didn't get an answer. So:

An entity bean's ejbCreate(...) method MUST return the primary key. That is
not a problem, if I specify the primary key myself and pass it to the
create(...) method.

But I want to let the database assign the primary key by creating a table
with an AUTOINCREMENT default for the primary key column, like in this
example using Cloudscape (part of SUN's J2EE v1.3):

create table myTable(
   id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
   someString VARCHAR(6),
   etc.
);

Then I can use INSERT like this:
   INSERT INTO mytable ( someString ) VALUES ( 'Hello' );

The database then assigns a unique value to the id column of that new
record.

If I do this in the ejbCreate(...) method of my bean my problem is: How do
I know that value in order to return it? Is that possible?

Thanks

Ralph Jensen


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-04 Thread Vinay Menon
Why don't you just use a primary key generator bean to encapsulate the key genaration? The ejbCreate can then work off that ejb and assign the primary key field tothe primary key generated field? so your autoincrement essentially will not be on the same table as the ejb but a different one and the primary key generator will work off that table. [Also makes sure that you have complete protability in terms of the database server!]  Vinay   - Original Message - From:Ralph Jensen Sent:Friday, May 04, 2001 8:52 AM To:[EMAIL PROTECTED] Subject:[JBoss-user] EJB question I asked this question elsewhere, but didn't get an answer. So:An entity bean's ejbCreate(...) method MUST return the primary key. That isnot a problem, if I specify the primary key myself and pass it to thecreate(...) method.But I want to let the database assign the primary key by creating a tablewith an AUTOINCREMENT default for the primary key column, like in thisexample using Cloudscape (part of SUN's J2EE v1.3):create table myTable( id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY, someString VARCHAR(6), etc.);Then I can use INSERT like this: INSERT INTO mytable ( someString ) VALUES ( 'Hello' );The database then assigns a unique value to the id column of that newrecord.If I do this in the ejbCreate(...) method of my bean my problem is: How doI know that value in order to return it? Is that possible?ThanksRalph Jensen___JBoss-user mailing list[EMAIL PROTECTED]http://lists.sourceforge.net/lists/listinfo/jboss-user Get your FREE download of MSN Explorer at http://explorer.msn.com


RE: [JBoss-user] EJB question

2001-05-04 Thread Jim Brownfield

I believe this is dependent upon the underlying database implementation.
For instance, in Informix, if you have an autoincrement (called SERIAL type
in Informix), you could make the function call DBINFO( 'sqlca.sqlerrd1' )
to get the last value of a serial type that was created by the database
thread.  There's probably a way to do this in the database you're using (I'm
not familiar with Cloudscape).

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Ralph Jensen
 Sent: Friday, May 04, 2001 12:09 AM
 To: [EMAIL PROTECTED]
 Subject: [JBoss-user] EJB question


 I asked this question elsewhere, but didn't get an answer. So:

 An entity bean's ejbCreate(...) method MUST return the primary
 key. That is
 not a problem, if I specify the primary key myself and pass it to the
 create(...) method.

 But I want to let the database assign the primary key by creating a table
 with an AUTOINCREMENT default for the primary key column, like in this
 example using Cloudscape (part of SUN's J2EE v1.3):

 create table myTable(
id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
someString VARCHAR(6),
etc.
 );

 Then I can use INSERT like this:
INSERT INTO mytable ( someString ) VALUES ( 'Hello' );

 The database then assigns a unique value to the id column of that new
 record.

 If I do this in the ejbCreate(...) method of my bean my problem is: How do
 I know that value in order to return it? Is that possible?

 Thanks

 Ralph Jensen


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-04 Thread Ralph Jensen

The portability would be there in terms of data access. How to tell the
database to autoincrement when I create a table is probably always database
specific. Or not?

I'm not good at SQL. So how would your suggestion look in code? What would
the key generator bean look like? Off which table would it work?

Ralph

- Original Message -
From: Vinay Menon [EMAIL PROTECTED]
To: JBOSS [EMAIL PROTECTED]
Sent: Friday, May 04, 2001 4:29 PM
Subject: Re: [JBoss-user] EJB question


Why don't you just use a primary key generator bean to encapsulate the key
genaration? The ejbCreate can then work off that ejb and assign the primary
key field to the primary key generated field? so your autoincrement
essentially will not be on the same table as the ejb but a different one
and the primary key generator will work off that table. [Also makes sure
that you have complete protability in terms of the database server!]

Vinay



- Original Message -
From: Ralph Jensen
Sent: Friday, May 04, 2001 8:52 AM
To: [EMAIL PROTECTED]
Subject: [JBoss-user] EJB question


I asked this question elsewhere, but didn't get an answer. So:

An entity bean's ejbCreate(...) method MUST return the primary key. That is
not a problem, if I specify the primary key myself and pass it to the
create(...) method.

But I want to let the database assign the primary key by creating a table
with an AUTOINCREMENT default for the primary key column, like in this
example using Cloudscape (part of SUN's J2EE v1.3):

create table myTable(
   id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
   someString VARCHAR(6),
   etc.
);

Then I can use INSERT like this:
   INSERT INTO mytable ( someString ) VALUES ( 'Hello' );

The database then assigns a unique value to the id column of that new
record.

If I do this in the ejbCreate(...) method of my bean my problem is: How do
I know that value in order to return it? Is that possible?

Thanks

Ralph Jensen


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-userbr clear=allhrGet
your FREE download of MSN Explorer at a
href=http://explorer.msn.com;http://explorer.msn.com/abr/p



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-04 Thread Jim Downing

Check out www.activescript.co.uk for a non-free ($99) component to generate
unique ids. The author has also posted the pattern on theserverside.com, so
you have something to work to if you want to implement it yourself.

jim

- Original Message -
From: Ralph Jensen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, May 04, 2001 10:25 AM
Subject: Re: [JBoss-user] EJB question


 The portability would be there in terms of data access. How to tell the
 database to autoincrement when I create a table is probably always
database
 specific. Or not?

 I'm not good at SQL. So how would your suggestion look in code? What would
 the key generator bean look like? Off which table would it work?

 Ralph

 - Original Message -
 From: Vinay Menon [EMAIL PROTECTED]
 To: JBOSS [EMAIL PROTECTED]
 Sent: Friday, May 04, 2001 4:29 PM
 Subject: Re: [JBoss-user] EJB question


 Why don't you just use a primary key generator bean to encapsulate the key
 genaration? The ejbCreate can then work off that ejb and assign the
primary
 key field to the primary key generated field? so your autoincrement
 essentially will not be on the same table as the ejb but a different one
 and the primary key generator will work off that table. [Also makes sure
 that you have complete protability in terms of the database server!]

 Vinay



 - Original Message -
 From: Ralph Jensen
 Sent: Friday, May 04, 2001 8:52 AM
 To: [EMAIL PROTECTED]
 Subject: [JBoss-user] EJB question


 I asked this question elsewhere, but didn't get an answer. So:

 An entity bean's ejbCreate(...) method MUST return the primary key. That
is
 not a problem, if I specify the primary key myself and pass it to the
 create(...) method.

 But I want to let the database assign the primary key by creating a table
 with an AUTOINCREMENT default for the primary key column, like in this
 example using Cloudscape (part of SUN's J2EE v1.3):

 create table myTable(
id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
someString VARCHAR(6),
etc.
 );

 Then I can use INSERT like this:
INSERT INTO mytable ( someString ) VALUES ( 'Hello' );

 The database then assigns a unique value to the id column of that new
 record.

 If I do this in the ejbCreate(...) method of my bean my problem is: How do
 I know that value in order to return it? Is that possible?

 Thanks

 Ralph Jensen


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-userbr
clear=allhrGet
 your FREE download of MSN Explorer at a
 href=http://explorer.msn.com;http://explorer.msn.com/abr/p



 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user




___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-04 Thread Ralph Jensen

Thanks. But that is actually much more than I want. I only need a unique
INT for primary keys.

For the moment I will try this:

In the sql-script:

create table uniqueInteger(
pk INTEGER constraint pk_unique primary key,
uniqueID INTEGER
);

insert into uniqueInteger VALUES( 1, 1 );


Then in the bean:
SELECT uniqueID from uniqeInteger;

save uniqueID in variable ( let's call it 'uniqueVar' )

then:

UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;


I think that's basically Vinay's suggestion. Does that look reasonable?
That's a lot of database access to get a unique primary key, just to be
able to return it from ejbCreate() - especially in light of the fact, that
databases do it automatically, if the table is created accordingly. Isn't
this kind of thing done regularly?


I know this has nothing to do with jBoss. Thank you.  :-)

Ralph

- Original Message -
From: Jim Downing [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, May 04, 2001 5:47 PM
Subject: Re: [JBoss-user] EJB question


 Check out www.activescript.co.uk for a non-free ($99) component to
generate
 unique ids. The author has also posted the pattern on theserverside.com,
so
 you have something to work to if you want to implement it yourself.

 jim

 - Original Message -
 From: Ralph Jensen [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, May 04, 2001 10:25 AM
 Subject: Re: [JBoss-user] EJB question


  The portability would be there in terms of data access. How to tell the
  database to autoincrement when I create a table is probably always
 database
  specific. Or not?
 
  I'm not good at SQL. So how would your suggestion look in code? What
would
  the key generator bean look like? Off which table would it work?
 
  Ralph
 
  - Original Message -
  From: Vinay Menon [EMAIL PROTECTED]
  To: JBOSS [EMAIL PROTECTED]
  Sent: Friday, May 04, 2001 4:29 PM
  Subject: Re: [JBoss-user] EJB question
 
 
  Why don't you just use a primary key generator bean to encapsulate the
key
  genaration? The ejbCreate can then work off that ejb and assign the
 primary
  key field to the primary key generated field? so your autoincrement
  essentially will not be on the same table as the ejb but a different
one
  and the primary key generator will work off that table. [Also makes
sure
  that you have complete protability in terms of the database server!]
 
  Vinay
 
 
 
  - Original Message -
  From: Ralph Jensen
  Sent: Friday, May 04, 2001 8:52 AM
  To: [EMAIL PROTECTED]
  Subject: [JBoss-user] EJB question
 
 
  I asked this question elsewhere, but didn't get an answer. So:
 
  An entity bean's ejbCreate(...) method MUST return the primary key.
That
 is
  not a problem, if I specify the primary key myself and pass it to the
  create(...) method.
 
  But I want to let the database assign the primary key by creating a
table
  with an AUTOINCREMENT default for the primary key column, like in this
  example using Cloudscape (part of SUN's J2EE v1.3):
 
  create table myTable(
 id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
 someString VARCHAR(6),
 etc.
  );
 
  Then I can use INSERT like this:
 INSERT INTO mytable ( someString ) VALUES ( 'Hello' );
 
  The database then assigns a unique value to the id column of that new
  record.
 
  If I do this in the ejbCreate(...) method of my bean my problem is: How
do
  I know that value in order to return it? Is that possible?
 
  Thanks
 
  Ralph Jensen
 
 
  ___
  JBoss-user mailing list
  [EMAIL PROTECTED]
  http://lists.sourceforge.net/lists/listinfo/jboss-userbr
 clear=allhrGet
  your FREE download of MSN Explorer at a
  href=http://explorer.msn.com;http://explorer.msn.com/abr/p
 
 
 
  ___
  JBoss-user mailing list
  [EMAIL PROTECTED]
  http://lists.sourceforge.net/lists/listinfo/jboss-user
 
 


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] EJB question

2001-05-04 Thread Deadman, Hal

Take a look at the key generator that comes with Exolab's Castor
(open-source). http://castor.exolab.org/key-generator.html

You probably want something like their HIGH/LOW generator. I haven't used it
but I use a similiar technique that I wrote myself. I like their
implementation better because they let you use different key gen techniques
that you can specify in the config file without changing code. They offer a
max+1 option which you should stay away from b/c I don't see how that could
guarantee uniqueness.

The castor high/low generator uses a database but it grabs a range of values
with each db hit so you don't hit the db everytime.

Hal

 -Original Message-
 From: Ralph Jensen [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 04, 2001 7:27 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [JBoss-user] EJB question


 Thanks. But that is actually much more than I want. I only
 need a unique
 INT for primary keys.

 For the moment I will try this:

 In the sql-script:

 create table uniqueInteger(
 pk INTEGER constraint pk_unique primary key,
 uniqueID INTEGER
 );

 insert into uniqueInteger VALUES( 1, 1 );


 Then in the bean:
 SELECT uniqueID from uniqeInteger;

 save uniqueID in variable ( let's call it 'uniqueVar' )

 then:

 UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;


 I think that's basically Vinay's suggestion. Does that look
 reasonable?
 That's a lot of database access to get a unique primary key,
 just to be
 able to return it from ejbCreate() - especially in light of
 the fact, that
 databases do it automatically, if the table is created
 accordingly. Isn't
 this kind of thing done regularly?


 I know this has nothing to do with jBoss. Thank you.  :-)

 Ralph

 - Original Message -
 From: Jim Downing [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, May 04, 2001 5:47 PM
 Subject: Re: [JBoss-user] EJB question


  Check out www.activescript.co.uk for a non-free ($99) component to
 generate
  unique ids. The author has also posted the pattern on
 theserverside.com,
 so
  you have something to work to if you want to implement it yourself.
 
  jim
 
  - Original Message -
  From: Ralph Jensen [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, May 04, 2001 10:25 AM
  Subject: Re: [JBoss-user] EJB question
 
 
   The portability would be there in terms of data access.
 How to tell the
   database to autoincrement when I create a table is probably always
  database
   specific. Or not?
  
   I'm not good at SQL. So how would your suggestion look in
 code? What
 would
   the key generator bean look like? Off which table would it work?
  
   Ralph
  
   - Original Message -
   From: Vinay Menon [EMAIL PROTECTED]
   To: JBOSS [EMAIL PROTECTED]
   Sent: Friday, May 04, 2001 4:29 PM
   Subject: Re: [JBoss-user] EJB question
  
  
   Why don't you just use a primary key generator bean to
 encapsulate the
 key
   genaration? The ejbCreate can then work off that ejb and
 assign the
  primary
   key field to the primary key generated field? so your
 autoincrement
   essentially will not be on the same table as the ejb but
 a different
 one
   and the primary key generator will work off that table.
 [Also makes
 sure
   that you have complete protability in terms of the
 database server!]
  
   Vinay
  
  
  
   - Original Message -
   From: Ralph Jensen
   Sent: Friday, May 04, 2001 8:52 AM
   To: [EMAIL PROTECTED]
   Subject: [JBoss-user] EJB question
  
  
   I asked this question elsewhere, but didn't get an answer. So:
  
   An entity bean's ejbCreate(...) method MUST return the
 primary key.
 That
  is
   not a problem, if I specify the primary key myself and
 pass it to the
   create(...) method.
  
   But I want to let the database assign the primary key by
 creating a
 table
   with an AUTOINCREMENT default for the primary key column,
 like in this
   example using Cloudscape (part of SUN's J2EE v1.3):
  
   create table myTable(
  id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
  someString VARCHAR(6),
  etc.
   );
  
   Then I can use INSERT like this:
  INSERT INTO mytable ( someString ) VALUES ( 'Hello' );
  
   The database then assigns a unique value to the id column
 of that new
   record.
  
   If I do this in the ejbCreate(...) method of my bean my
 problem is: How
 do
   I know that value in order to return it? Is that possible?
  
   Thanks
  
   Ralph Jensen
  
  
   ___
   JBoss-user mailing list
   [EMAIL PROTECTED]
   http://lists.sourceforge.net/lists/listinfo/jboss-userbr
  clear=allhrGet
   your FREE download of MSN Explorer at a
   href=http://explorer.msn.com;http://explorer.msn.com/abr/p
  
  
  
   ___
   JBoss-user mailing list
   [EMAIL PROTECTED]
   http://lists.sourceforge.net/lists/listinfo/jboss-user
  
  
 
 
  ___
  JBoss-user mailing list

Re: [JBoss-user] EJB question

2001-05-04 Thread James Cook

- Original Message -
From: Ralph Jensen [EMAIL PROTECTED]

 For the moment I will try this:

 In the sql-script:

 create table uniqueInteger(
 pk INTEGER constraint pk_unique primary key,
 uniqueID INTEGER
 );

 insert into uniqueInteger VALUES( 1, 1 );


 Then in the bean:
 SELECT uniqueID from uniqeInteger;

 save uniqueID in variable ( let's call it 'uniqueVar' )

 then:

 UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;


 I think that's basically Vinay's suggestion. Does that look reasonable?

Nope. It doesn't handle concurrent access. Anytime you separate your read from
your update you are open to concurrency issues. If you are going to take this
route, you will have to obtain a table lock...which is going to be db specific.

There is much discussion on this topic in most SQL books, and also on
theserverside.com are a few threads.

jim


 - Original Message -
 From: Jim Downing [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, May 04, 2001 5:47 PM
 Subject: Re: [JBoss-user] EJB question


  Check out www.activescript.co.uk for a non-free ($99) component to
 generate
  unique ids. The author has also posted the pattern on theserverside.com,
 so
  you have something to work to if you want to implement it yourself.
 
  jim
 
  - Original Message -
  From: Ralph Jensen [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, May 04, 2001 10:25 AM
  Subject: Re: [JBoss-user] EJB question
 
 
   The portability would be there in terms of data access. How to tell the
   database to autoincrement when I create a table is probably always
  database
   specific. Or not?
  
   I'm not good at SQL. So how would your suggestion look in code? What
 would
   the key generator bean look like? Off which table would it work?
  
   Ralph
  
   - Original Message -
   From: Vinay Menon [EMAIL PROTECTED]
   To: JBOSS [EMAIL PROTECTED]
   Sent: Friday, May 04, 2001 4:29 PM
   Subject: Re: [JBoss-user] EJB question
  
  
   Why don't you just use a primary key generator bean to encapsulate the
 key
   genaration? The ejbCreate can then work off that ejb and assign the
  primary
   key field to the primary key generated field? so your autoincrement
   essentially will not be on the same table as the ejb but a different
 one
   and the primary key generator will work off that table. [Also makes
 sure
   that you have complete protability in terms of the database server!]
  
   Vinay
  
  
  
   - Original Message -
   From: Ralph Jensen
   Sent: Friday, May 04, 2001 8:52 AM
   To: [EMAIL PROTECTED]
   Subject: [JBoss-user] EJB question
  
  
   I asked this question elsewhere, but didn't get an answer. So:
  
   An entity bean's ejbCreate(...) method MUST return the primary key.
 That
  is
   not a problem, if I specify the primary key myself and pass it to the
   create(...) method.
  
   But I want to let the database assign the primary key by creating a
 table
   with an AUTOINCREMENT default for the primary key column, like in this
   example using Cloudscape (part of SUN's J2EE v1.3):
  
   create table myTable(
  id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,
  someString VARCHAR(6),
  etc.
   );
  
   Then I can use INSERT like this:
  INSERT INTO mytable ( someString ) VALUES ( 'Hello' );
  
   The database then assigns a unique value to the id column of that new
   record.
  
   If I do this in the ejbCreate(...) method of my bean my problem is: How
 do
   I know that value in order to return it? Is that possible?
  
   Thanks
  
   Ralph Jensen
  
  
   ___
   JBoss-user mailing list
   [EMAIL PROTECTED]
   http://lists.sourceforge.net/lists/listinfo/jboss-userbr
  clear=allhrGet
   your FREE download of MSN Explorer at a
   href=http://explorer.msn.com;http://explorer.msn.com/abr/p
  
  
  
   ___
   JBoss-user mailing list
   [EMAIL PROTECTED]
   http://lists.sourceforge.net/lists/listinfo/jboss-user
  
  
 
 
  ___
  JBoss-user mailing list
  [EMAIL PROTECTED]
  http://lists.sourceforge.net/lists/listinfo/jboss-user


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB question

2001-05-04 Thread Vinay Menon
Ralph,  Just to add that the autoincrement needn't be database specific... your ejb could just have   keyValue = keyValue+1;  where keyValue maps to the underlying column in the database table.  That way autoincrement is not database specific! If you want to use to the database specific primary key generation you could do so.  regards.  Vinay   - Original Message - From:Ralph Jensen Sent:Friday, May 04, 2001 1:09 PM To:[EMAIL PROTECTED] Subject:Re: [JBoss-user] EJB question Thanks. But that is actually much more than I want. I only need a uniqueINT for primary keys.For the moment I will try this:In the sql-script:create table uniqueInteger( pk INTEGER constraint pk_unique primary key, uniqueID INTEGER);insert into uniqueInteger VALUES( 1, 1 );Then in the bean:SELECT uniqueID from uniqeInteger;save uniqueID in variable ( let's call it 'uniqueVar' )then:UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;I think that's basically Vinay's suggestion. Does that look reasonable?That's a lot of database access to get a unique primary key, just to beable to return it from ejbCreate() - especially in light of the fact, thatdatabases do it automatically, if the table is created accordingly. Isn'tthis kind of thing done regularly?I know this has nothing to do with jBoss. Thank you. :-)Ralph- Original Message -From: Jim Downing [EMAIL PROTECTED]To: [EMAIL PROTECTED]Sent: Friday, May 04, 2001 5:47 PMSubject: Re: [JBoss-user] EJB question Check out www.activescript.co.uk for a non-free ($99) component togenerate unique ids. The author has also posted the pattern on theserverside.com,so you have something to work to if you want to implement it yourself. jim - Original Message - From: "Ralph Jensen" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, May 04, 2001 10:25 AM Subject: Re: [JBoss-user] EJB question  The portability would be there in terms of data access. How to tell the  database to autoincrement when I create a table is probably always database  specific. Or not?   I'm not good at SQL. So how would your suggestion look in code? Whatwould  the key generator bean look like? Off which table would it work?   Ralph   - Original Message -  From: Vinay Menon [EMAIL PROTECTED]  To: JBOSS [EMAIL PROTECTED]  Sent: Friday, May 04, 2001 4:29 PM  Subject: Re: [JBoss-user] EJB questionWhy don't you just use a primary key generator bean to encapsulate thekey  genaration? The ejbCreate can then work off that ejb and assign the primary  key field to the primary key generated field? so your autoincrement  essentially will not be on the same table as the ejb but a differentone  and the primary key generator will work off that table. [Also makessure  that you have complete protability in terms of the database server!]   Vinay - Original Message -  From: Ralph Jensen  Sent: Friday, May 04, 2001 8:52 AM  To: [EMAIL PROTECTED]  Subject: [JBoss-user] EJB questionI asked this question elsewhere, but didn't get an answer. So:   An entity bean's ejbCreate(...) method MUST return the primary key.That is  not a problem, if I specify the primary key myself and pass it to the  create(...) method.   But I want to let the database assign the primary key by creating atable  with an AUTOINCREMENT default for the primary key column, like in this  example using Cloudscape (part of SUN's J2EE v1.3):   create table myTable(  id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,  someString VARCHAR(6),  etc.  );   Then I can use INSERT like this:  INSERT INTO mytable ( someString ) VALUES ( 'Hello' );   The database then assigns a unique value to the id column of that new  record.   If I do this in the ejbCreate(...) method of my bean my problem is: Howdo  I know that value in order to return it? Is that possible?   Thanks   Ralph Jensen___  JBoss-user mailing list  [EMAIL PROTECTED]  http://lists.sourceforge.net/lists/listinfo/jboss-userbr clear=allhrGet  your FREE download of MSN Explorer at a  href="http://explorer.msn.com"http://explorer.msn.com/abr/p ___  JBoss-user mailing list  [EMAIL PROTECTED]  http://lists.sourceforge.net/lists/listinfo/jboss-user   ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user___JBoss-user mailing list[EMAIL PROTECTED]http://lists.sourceforge.net/lists/listinfo/jboss-user Get your FREE download of MSN Explorer at http://explorer.msn.com


RE: [JBoss-user] EJB question

2001-05-04 Thread Jim Brownfield



I don't think this will 
work unless you are willing to lock the entire table before you execute 
this. Otherwise, you will have a race condition for the unique 
key.

Jim

  -Original Message-From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]]On Behalf Of Vinay 
  MenonSent: Friday, May 04, 2001 2:21 PMTo: 
  JBOSSSubject: Re: [JBoss-user] EJB question
  Ralph,
   Just to add that the autoincrement needn't be database 
  specific... your ejb could just have 
  
  keyValue = keyValue+1;
  
  where keyValue maps to the underlying column in the database 
  table.
  
  That way autoincrement is not database specific! If you want to use to 
  the database specific primary key generation you could do so.
  
  regards.
  
  Vinay
  
  
- Original Message -
From:Ralph 
Jensen
Sent:Friday, May 04, 2001 1:09 
PM
To:[EMAIL PROTECTED]
Subject:Re: [JBoss-user] EJB 
question
Thanks. But that is actually much more than I want. I only 
need a uniqueINT for primary keys.For the moment I will try 
this:In the sql-script:create table 
uniqueInteger( pk INTEGER constraint pk_unique primary 
key, uniqueID INTEGER);insert into 
uniqueInteger VALUES( 1, 1 );Then in the bean:SELECT 
uniqueID from uniqeInteger;save uniqueID in variable ( let's call it 
'uniqueVar' )then:UPDATE uniqueInteger SET uniqueID = 
uniqueVar+1 WHERE pk = 1;I think that's basically Vinay's 
suggestion. Does that look reasonable?That's a lot of database access to 
get a unique primary key, just to beable to return it from ejbCreate() - 
especially in light of the fact, thatdatabases do it automatically, if 
the table is created accordingly. Isn'tthis kind of thing done 
regularly?I know this has nothing to do with jBoss. Thank 
you. :-)Ralph- Original Message -From: Jim 
Downing [EMAIL PROTECTED]To: 
[EMAIL PROTECTED]Sent: Friday, May 04, 2001 5:47 
PMSubject: Re: [JBoss-user] EJB question Check out 
www.activescript.co.uk for a non-free ($99) component togenerate 
unique ids. The author has also posted the pattern on 
theserverside.com,so you have something to work to if you want 
to implement it yourself. jim - Original 
Message - From: "Ralph Jensen" [EMAIL PROTECTED] 
To: [EMAIL PROTECTED] Sent: Friday, May 04, 
2001 10:25 AM Subject: Re: [JBoss-user] EJB 
    question  The portability would be there in 
terms of data access. How to tell the  database to autoincrement 
when I create a table is probably always database  
specific. Or not?   I'm not good at SQL. So how 
would your suggestion look in code? Whatwould  the key 
generator bean look like? Off which table would it work? 
  Ralph   - Original Message 
-  From: Vinay Menon [EMAIL PROTECTED]  
To: JBOSS [EMAIL PROTECTED]  Sent: 
Friday, May 04, 2001 4:29 PM  Subject: Re: [JBoss-user] EJB 
    questionWhy don't you just use a 
primary key generator bean to encapsulate thekey  
genaration? The ejbCreate can then work off that ejb and assign the 
primary  key field to the primary key generated field? so your 
autoincrement  essentially will not be on the same table as the 
ejb but a differentone  and the primary key generator will 
work off that table. [Also makessure  that you have complete 
protability in terms of the database server!]   
Vinay - Original 
Message -  From: Ralph Jensen  Sent: Friday, May 
04, 2001 8:52 AM  To: [EMAIL PROTECTED] 
 Subject: [JBoss-user] EJB question   
 I asked this question elsewhere, but didn't get an answer. So: 
  An entity bean's ejbCreate(...) method MUST return the 
primary key.That is  not a problem, if I specify the 
primary key myself and pass it to the  create(...) 
method.   But I want to let the database assign the 
primary key by creating atable  with an AUTOINCREMENT 
default for the primary key column, like in this  example using 
Cloudscape (part of SUN's J2EE v1.3):   create table 
myTable(  id INT DEFAULT AUTOINCREMENT 
CONSTRAINT pk_id PRIMARY KEY,  someString 
VARCHAR(6),  etc.  ); 
  Then I can use INSERT like this: 
 INSERT INTO mytable ( someString ) VALUES ( 'Hello' 
);   The database then assigns a unique value to the 
id column of that new  record.   If I do 
this in the ejbCreate(...) method of my bean my problem is: 
Howdo  I know that value in order to return it? Is that 
possible?   Thanks   Ralph 
Jensen
___  JBoss-user 
mailing list  [EMAIL PROTECTED]  
http://lists.sourceforge.net/lists/listinfo/jboss-userbr 
clear=allhrGet  your FREE download of MSN Explorer 
at a  
href="http://explorer.msn.com"http://explorer.msn.com/abr/p 

___  JBoss-us

Re: [JBoss-user] EJB question

2001-05-04 Thread Vinay Menon
Am assuming  a. Number of inserts into a table is usually low as compared to reads and updates. b. Read is a fairly lightweight operation.  All this is if portability is required! And needless to say there is a price to pay!  Of course, do let me know you are aware of any other options.   Vinay   - Original Message - From:Jim Brownfield Sent:Saturday, May 05, 2001 12:02 AM To:[EMAIL PROTECTED] Subject:RE: [JBoss-user] EJB question   I don't think this will work unless you are willing to lock the entire table before you execute this. Otherwise, you will have a race condition for the unique key.  Jim  -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Vinay MenonSent: Friday, May 04, 2001 2:21 PMTo: JBOSSSubject: Re: [JBoss-user] EJB question Ralph,  Just to add that the autoincrement needn't be database specific... your ejb could just have   keyValue = keyValue+1;  where keyValue maps to the underlying column in the database table.  That way autoincrement is not database specific! If you want to use to the database specific primary key generation you could do so.  regards.  Vinay   - Original Message - From:Ralph Jensen Sent:Friday, May 04, 2001 1:09 PM To:[EMAIL PROTECTED] Subject:Re: [JBoss-user] EJB question Thanks. But that is actually much more than I want. I only need a uniqueINT for primary keys.For the moment I will try this:In the sql-script:create table uniqueInteger( pk INTEGER constraint pk_unique primary key, uniqueID INTEGER);insert into uniqueInteger VALUES( 1, 1 );Then in the bean:SELECT uniqueID from uniqeInteger;save uniqueID in variable ( let's call it 'uniqueVar' )then:UPDATE uniqueInteger SET uniqueID = uniqueVar+1 WHERE pk = 1;I think that's basically Vinay's suggestion. Does that look reasonable?That's a lot of database access to get a unique primary key, just to beable to return it from ejbCreate() - especially in light of the fact, thatdatabases do it automatically, if the table is created accordingly. Isn'tthis kind of thing done regularly?I know this has nothing to do with jBoss. Thank you. :-)Ralph- Original Message -From: Jim Downing [EMAIL PROTECTED]To: [EMAIL PROTECTED]Sent: Friday, May 04, 2001 5:47 PMSubject: Re: [JBoss-user] EJB question Check out www.activescript.co.uk for a non-free ($99) component togenerate unique ids. The author has also posted the pattern on theserverside.com,so you have something to work to if you want to implement it yourself. jim - Original Message - From: "Ralph Jensen" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, May 04, 2001 10:25 AM Subject: Re: [JBoss-user] EJB question  The portability would be there in terms of data access. How to tell the  database to autoincrement when I create a table is probably always database  specific. Or not?   I'm not good at SQL. So how would your suggestion look in code? Whatwould  the key generator bean look like? Off which table would it work?   Ralph   - Original Message -  From: Vinay Menon [EMAIL PROTECTED]  To: JBOSS [EMAIL PROTECTED]  Sent: Friday, May 04, 2001 4:29 PM  Subject: Re: [JBoss-user] EJB questionWhy don't you just use a primary key generator bean to encapsulate thekey  genaration? The ejbCreate can then work off that ejb and assign the primary  key field to the primary key generated field? so your autoincrement  essentially will not be on the same table as the ejb but a differentone  and the primary key generator will work off that table. [Also makessure  that you have complete protability in terms of the database server!]   Vinay - Original Message -  From: Ralph Jensen  Sent: Friday, May 04, 2001 8:52 AM  To: [EMAIL PROTECTED]  Subject: [JBoss-user] EJB questionI asked this question elsewhere, but didn't get an answer. So:   An entity bean's ejbCreate(...) method MUST return the primary key.That is  not a problem, if I specify the primary key myself and pass it to the  create(...) method.   But I want to let the database assign the primary key by creating atable  with an AUTOINCREMENT default for the primary key column, like in this  example using Cloudscape (part of SUN's J2EE v1.3):   create table myTable(  id INT DEFAULT AUTOINCREMENT CONSTRAINT pk_id PRIMARY KEY,  someString VARCHAR(6),  etc.  );   Then I can use INSERT like this:  INSERT INTO mytable ( someString ) VALUES ( 'Hello' );   The database then assigns a unique value to the id column of that new  record.   If I do this in the ejbCreate(...) method of my bean my problem is: Howdo  I know that value in order to return it? Is that possible?   Thanks   Ralph Jensen___  JBoss-user mailing list  [EMAIL PROTECTED]  http://lists.sourceforge.net/lists/listinfo/jboss-userbr clear=allhrGet  your FREE download of MSN Explorer at a  href="http://explorer.msn.com"http://explorer.msn.com/abr/p ___  JBoss-user mailing li

Re: [JBoss-user] EJB Question

2001-04-26 Thread danch

Daniel Cardin wrote:

 I am definitely not an expert on that topic, but I'd like to add my
 comments :)
 
 For one, beans have the advantage of running in the context of the
 server. So you can assume that JBoss will manage security and
 transactions if you so desire. This by itself is already worth
 something, IMHO.

Especially the transaction support.


 
 You have also access to all internal ressources like DataSources (not
 available outside the context of the server). 
 As well, if your session bean (implementing business code) needs to use
 Entity beans, they could run within the same JVM. This sort of intra-JVM
 type of communication is optimized in JBoss, so that calls that would go
 through RMI are handled as normal method calls. (This is how I
 understand it... hope it's correct :)) 

Nearly as a normal method call. The spec dictates that the method calls 
always behave as though they're remote insofar as passing of references 
go. This can be turned off for performance reasons.


 
 If you use stateless session beans, code can be pooled and reused by the
 server to serve many clients in succession. 

Comparing this to a non-ejb helper that's used (for example) as a bean 
on a JSP page, you should save a lot of memory and garbage collection 
overhead.


-danch


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] EJB Question

2001-04-26 Thread David Jencks

Hi,

From a practical standpoint, usually entity beans have 'individual field'
data access methods, and usually when you have a business process step,
more than one field is affected.  To get all the modifications in one
transaction without jumping through external transaction control hoops and
obviating the main reason you got an app server in the first place, put a
method that does all the changes at once in a session bean.  Automatically
( unless you mess with the transaction attributes of the methods)
everything is in one transaction.

From an architectural standpoint, the entity beans pretty much represent a
data access layer, session beans expose a business process interface, the
flow control outside the ejb container a presentation manager, and what
actually makes the ui such as jsps a presentation layer.  Mixing up any of
these layers, such as exposing the data access interface to the
presentation manager layer, means _much_ more difficulty when it comes time
to extend or replace a layer.

Hope this helps

david jencks

On 2001.04.26 16:17:56 -0400 Michael Hustler wrote:
 I have a general (and likely simple) question about EJB's - session beans
 in
 particular.
 
 What are the advantages of a stateless session bean over a non EJB helper
 class provided to clients.
 
 Thanks,
 -mike.
 
 
 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user
 


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user