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

Reply via email to