• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use a Timestamp as the Identifier

 
Darryl Williams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a mapping in hibernate that has a <id> that
1) is a Timestamp (yyyy/mm/dd.hh.mm.ss.sss) (not a DateTime)
2) using a MYSQL database
3) where I provide the Timestamp value using my getters and setters and is not automaticly assigned by the JVM or DB.
4) that will not change when I update the record in the DB.

I am using:
1) MYSQL 5.2.26
2) Hibernate 3

How should I change the mapping (hbm.xml) so that it stops changing the Timestamp value when a update occurs. I only what the timestamp value assigned when writing a new record and from that point forward it should not change.
How should I change the mapping (hbm.xml) so that I get the microseconds because currently I only get data in MYSQL in the following format yyyy/mm/dd.hh.mm.ss. I wan/need to micro seconds because I can generate more than 1 record per second.




 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... so that it stops changing the Timestamp value when a update occurs.

In what scenario this happens in your application?
 
Darryl Williams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I kind of found out why this was happenning.... I took a look at the Table in MYSQL and found the reason for this.


I'm not sure how to change this in the mapping but when the table was created (for MYSQL) by hibernate it created the Timestamp field with the default definitions as "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP". I don't know how to change my HBM.XML file to not use that default definition value so I just changed ALTERED the table the MYSQL workbench.

So when I update a record it is not changing the TIMESTAMP field value with a new(current) TIMESTAMP.
If anyone can tell me how to change the mapping to not set the default defintions to "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" I'd appreciate it.

thanks.

To answer your question "when does this occur". The short answer is whenever I perform a update(). I am writing transactions to my table/file and from time to time those transaction will need to be updated. The original posting of the transaction should not change (meaning the date/time (down to the milesecons) should not change) because the record changed. All records should retain their orginal posting Timestamp value not matter if it was updated or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic