I am new to J2EE and felt certain that my failure to know how do this had to do with that fact. But, I see plenty of statements like:
Quote:
Simply because composite-id are meant to be business keys, not technical one. So they can't be automatically generated.
and
Quote:
We regard this as an extremely strange thing to want to do. If you have a generated surrogate key, why not just make it be the primary key?
If composite keys cannot have generated fields then I need some DB advise.
I have a database for which data is going to be asynchronously replicated between several sites. Several of the tables to be replicated have generated keys. The key must be generate by the local database, but the primary key must be globally unique.
My normal solution to this problem is primary key (location_id, generated_id). But this is not supported and seems to be regarded as "extremely strange".
A second solution is to start the generated_id at a value that is determined by the location. On the practical front I think this is a pain because I would have to make certain that each location is assigned a range and should I trip I will have a mess. On an esthetic front I feel like doing this to id field makes it non atomic. (i.e. it is like location_id * 10^n + generated_id).
A third option is to have a local non replicated table that fires a trigger to populate a replicated table. The local table would not need the location id, but the global table could still be contain a globally unique primary key. Of coarse, this gives me two copies of the data.
So, what am I missing? What is the "right" way to do this?
BTW...The DB I was mandated to use does not have sequences. Which, sucks because I love sequences.