Generate a primary key without using a database

I recently came across a question that was for "Generating a primary key in a clustered environment of 5 application servers - [OAS version 10] without using a database."

Usually we generate PK using a DB sequence or store values ​​in a database table and then using SP to generate a new PK value ... However, the current requirement is to generate a primary key for my application without reference to the database using JDK 1.4.

Expert help is needed to come up with better ways to handle this.

Thank,

+5
source share
9 answers

UUID .

Edit:
, , -.

, ( ) , "" , , .

UUID - , ; , UUID , , . UUID ; , , , .

, ( ) ( , ) , .

con UUID - 16 , 4- int - 4 . ? , , , . , UUID, - , . SQL Server, Oracle , , SQL Server . auto-increment int . , , , -, , UUID (GUID Microsoft), , , , UUID, , . Oracle - , Oracle PKs , SQL Server.

, : UUID , !

+7

, UUID.

, , -

MAC address + time in nanseconds since 1970.
+3

, GUID/UUID - . , , HiLo.

+2

UUID. Java5 ( factory ). factory Java 1.4, .

+2

, Hibernate ( 5.1.5 ). . , , , .

, , :)

+2

, UUID() SHA1 ( ).

int, .

0

,

  • IP- MAC-
  • ( , , - )
0

Statement statement.getGeneratedKeys(); (), Statement.

Java doc

0

MongoDB: http://www.mongodb.org/display/DOCS/Object+IDs

.

Oracle Express , :

SQL > mysequence.nextval < 20;

NEXTVAL

     1
     2
     3
     4
     5
    ..  
    20

? (Oracle Express ) ? , Oracle ?

0

All Articles