aspose file tools*
The moose likes Object Relational Mapping and the fly likes Why Timestamp isn't allowed as a primary key? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Why Timestamp isn Watch "Why Timestamp isn New topic
Author

Why Timestamp isn't allowed as a primary key?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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

Joined: Dec 09, 2004
Posts: 34
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Timestamp isn't allowed as a primary key?