JR Ruggentaler <JR.Ruggentale..pv.com> wrote:
> I would like to generate a unique account number using Cayenne and MySQL.
This would be similar to the Cayenne primary key generation and as SAFE. The
account number would be a BIGINT MySQL type. How would I Model this and how
would I get the next unique account number using Cayenne APIs? The account
number would be similar to a credit card number (16 digits) and I DON'T want
to use the Entity's primary key as the account number.
The safe way to do this is using a system like Cayenne's default
database-independent pk generation where you have a table that stores the
last assigned value. Each time you need a new number, simply update that
value by whatever formula you like.
If this is the only likely use of such an algorithm, the one-field table
only needs to have one record with a manually-generated pk.
You can get fancier like Cayenne does and add an identifier to the record in
order to support multiple unique numbers.
Table: NUMERIC_ID_GENERATION
Field: NUMERIC_ID (manual pk)
Mark it as optimistic locking so any update guarantees a new number, then
pretty much execute the SQL you previously posted to get the new id and
update the db value.
Hopefully this isn't too confusing.
-Mike
This archive was generated by hypermail 2.0.0 : Sun Jan 16 2005 - 18:01:50 EST