cancel
Showing results for 
Search instead for 
Did you mean: 

Autoincremental database fields

Former Member
0 Kudos

Hello,

I am looking for a way to create autoincremental fields as keys in database tables. It should be a method like "generateID". Each call to "generateId" shall return a unique number which was incremented before. It should work in a multiuser environment, where multiple user demand simultaneously unique id's before creating new records in a table. Furthermore, it should be independent from which database I use and it should be maintainable in the Netweaver Developer Studio.

In several tutorials from SAP e.g. QuickCarRental, there is provided a method "generateID()" which works with a timestamp or so. The authors of the tutorials recommend, NOT to use such a functionality in live systems environments: "Make sure that the method used here, generateId(), is not used to implement an ID in a live system. In this case, we are simply simulating generating an ID. In a live system, always use the correct ID generation process."

But, what is the correct ID generation process ?

Thanks in advance

Andreas

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Andreas,

Take a look to this external article http://www.jguru.com/faq/view.jsp?EID=1030397

It might help you.

Regards.

Former Member
0 Kudos

Hello Antonio,

thank you for your answer. I think, the discussion at jguru's points to generating IDs similar/equal to guids. But this is not, what I am looking for. I am looking for a way to generate unique, autoincremental numeric values, e.g 1, 2, 3, 4, 5, ...

I could develop a serverside service which generates ascending numbers on demand, but how can I attain that it works in a multiuser environment and will give correct values after a server reboot ?

Do you know a design pattern which can be used for this ?

Kind regards

Andreas

Former Member
0 Kudos

Take a look to this:

http://jdj.sys-con.com/read/36169.htm

Your serverside service should reserve a set of IDs. Then you ask it for one of then whenever you need it. If your service runs out of IDs it must reserve some more.

Hope this helps.

Former Member
0 Kudos

Thanks again, Antonio. This seems to be the right way, using a singleton.

btw, I've found another interesting link at apache.

http://jakarta.apache.org/commons/sandbox/id/

The commons library ID generates ids in different characteristics, seems to be very usefull when it's out of sandbox.

Kind regeards Andreas