Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Timestamp isn't allowed as a primary key?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In JPA, whay Date objects are allowed to be used as primary keys for entities while Timestamp objects aren't?
Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea, but I was going to say that with Timestamps, it is possible that two records are added at the exact same moment, therefore not unique. But dates doesn't make sense unless they have a higher precision that can guarantee uniqueness.

Mark
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps I missed something in the spec, but I see nothing in JPA disallowing having a timestamp as a primary key or part of one. I'm pretty sure it is supported in the JPA reference impl.

In general you should be careful in doing so, as different databases support different precision of timestamp values (seconds, milliseconds, microsecond). Normally a generated sequential id is a much better way to go.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been reading "EJB 3 In Action", it indicates the at Timestamp couldn't be used as PK.
I think Date PK should also have this restriction.
 
Ravindra Rawat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using PK as date/timestamp would cause issues for distributed applications and probably thats why they are not allowed.

Googling result: http://www.mail-archive.com/pgsql-general@postgresql.org/msg86346.html

Thanks
Ravindra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic