Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

What PK generator strategy do developers prefer for enterprise web applications?  RSS feed

 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In enterprise applications like ecommerce, health, banking domain applications, How do developers usually take care of PK?
For any type of registration like user registration, test-report, some entity, which strategy of PK generator do developers use? I'm sure they don't have to assign the id everytime, there must be some auto-generating strategy they would be following.
Thanks.
 
Bartender
Posts: 20721
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends entirely on need.

For some tables a simple sequential ID generator is all that is necessary. For others, one or more columns form a natural unique ID and no generator is required at all. Still others might want an (ugh!) UUID. This is likely if there are many disconnected data sources and no master generator available. There is no one-size-fits-all solution.
 
Arun Singh Raaj
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

For others, one or more columns form a natural unique ID and no generator is required at all.


Do you write the logic for this in Business layer? Could you please provide an example or link to explain how it works? How to make sure the generated id will be unique?

 
Rancher
Posts: 427
6
Fedora IntelliJ IDE Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natural unique ID means that the data already has something that can be used as an ID. That's why you don't need a generator.....   You would have to use your own judgement to know if it will be unique.  If you have a date that has digits all the way to milliseconds and then the origin you could use that as an ID because something isn't going to come from the same place at the same millisecond.
 
Marshal
Posts: 24458
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's very common to just allow the database to generate the sequential ID which Tim mentioned. The database is in the business layer already, of course.

As for the case of a natural unique ID being represented by columns in the table, an example would be if a government agency used a Social Insurance Number as the primary key for a table containing taxpaying persons. There's no logic to be written for that, and how it works ought to be pretty obvious.

As for how to make sure that ID is unique... there are situations where people can fraudulently use somebody else's taxpayer ID. In this case it would be possible for duplicate ID's to occur. However the owners and designers of the system ought to be aware of that possibility in advance and design the system to deal with that situation. And note that this is not a "generated" ID, at least it's not generated by the application I have in mind. The ID comes from a source which is external to this application.
 
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!