This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, For the project i'm working on, i need to insert data to fill the tables in the database schema, what i'm trying to figure out is what is an efficient way to generate unique primary keys for each of the tables, as each table has to have a unique primary key, but that data is not going to be provided to my database bean... These primary don't have to be meaningful, they are just to uniquely identify each record and support relationships between the tables in the schema. I have some ideas, but i was hoping that someone who has already went through this would share the pattern. Thanks in advance, Dmitry
Many databases have database-specific ways to do this. SQL Server can autonumber primary keys. Oracle has sequences to generate numbers. Etcetera. If you don't want to be database-specific, use some type of service to generate these numbers (can be a class, bean, EJB, RMI or Corba callable service, whatever) in conjunction with a "nextnum" table. For best efficiency, if strictly consecutive numbers are not necessary, you grab a range of numbers from the nextnum table and only go back to the database once you've exhausted that range. With this technique you can have multiple, distributed number generators. - Peter