Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Surrogate auto-generated VS natural primary keys with JPA
Surrogate auto-generated VS natural primary keys with JPA [message #661628] Fri, 25 March 2011 11:38 Go to next message
Eclipse User is currently offline Eclipse User
Messages: 4
Registered: March 2011
Junior Member
I am trying to understand if the use of surrogate auto-generated primary keys even in relational database tables which have a proper natural primary key may provide any efficiency gain from a JPA perspective (EclipseLink 2.0 in particular). Personally I'd like to avoid surrogate keys if not needed, but I am not sure if this has some implication on JPA performance.

Any help is very much appreciated.
Thanks
Re: Surrogate auto-generated VS natural primary keys with JPA [message #661977 is a reply to message #661628] Mon, 28 March 2011 13:34 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If your natural Id is complex, then using a generated Id may provide some performance benefit.

If both are simple data-types, then I cannot see any benefit. Using the natural Id is probably more performant as people are more likely to query on it.

Generated Ids do have the benefit of always being unique, and never changing. Sometimes natural ids seemed to be unique or not change, but actually can change (such as ssn, name, phone number, email, etc.).


James : Wiki : Book : Blog : Twitter
Re: Surrogate auto-generated VS natural primary keys with JPA [message #662102 is a reply to message #661977] Tue, 29 March 2011 06:32 Go to previous message
Eclipse User is currently offline Eclipse User
Messages: 4
Registered: March 2011
Junior Member
Thanks James for taking your time to answer my question. I can see that you more or less apply concepts of relational database optimization, so I take it as if use of JPA should not affect the database design when it comes to efficiency matter.
Thanks.
Previous Topic:JPA2.1
Next Topic:Cascade persist and map keys
Goto Forum:
  


Current Time: Mon Jul 28 02:16:23 EDT 2014

Powered by FUDForum. Page generated in 0.01749 seconds