chris brat schrieb:
> Have you considered using an external sequence ?
Yes. I thought about stored procedures or I wanted to lookup the feature
of CMP EntityBeans. But these techniques require some time of
orientation. So I thought of something "quicker"
> 1.) Query the sequence for the id
that's what I thought of
or use your own generated id and keep
Own generated? Before I do the insert, i. d. I create my own id and use
it for al 3 inserts?
chris brat - 21 Apr 2006 21:55 GMT
Exactly. ;-)
Stored procedures are usually the best option because they are 'closer'
to the database and can usually be optimised. If you were going to use
CMP beans you would still need to generate or lookup the key before you
inserted your rows - if I remember correctly it isn't done for you.
Your application could generate the ids, either a combination of
machine name, location, timestamp etc, combinations of name, surname,
idno, date of birth - thought these are not always possible or
appropriate.
For the application I currently work on I set up a "sequence" table,
which is just a table with a varchar(10) and an int column, because the
database we use doesnt support sequences itself.
I then wrote a Sequencer class with one method getNext(String
sequenceName) that returns an int value representing the next value
(The method does a query and an update on the row without the rest of
my application knowing the logic - I'll replace it if we change
database or I find a better solution).
I then use this id for numerous inserts into 2 different tables. I't
may not be pretty but it does work.