I want to get surrogate keys for my user table(s) in MySQL. I'm sure concatinating an incrementing value + a timestamp would get me unique keys across multiple tables but how do I get the incremental value for the class's persistence table before I persist it to the database.
+1
A:
let hibernate do it for you using one of their key generators. If you must define your own key scheme, you will have to write your own generator.
hvgotcodes
2010-08-04 15:27:32
Is there anything wrong with getting the current system time in millis then assigning this as the ID? I want something a bit more unique then an auto-incrementing field (which is what an @Generated tag is giving me at the moment with MySQL). I want keys that will be unique across several tables not just one
2010-08-04 15:40:33
Yes, because, depending on the resolution of your database's CURRENT_TIMESTAMP, you could have two objects being inserted at the same exact moment in time. How can you get more unique than an auto-incrementing field, which is guaranteed to be unique already?
matt b
2010-08-04 15:46:50
How do you autoincrement accross multiple tables...
2010-08-04 15:49:23
@user398371, I don't think its possible with mysql to do that. Oracle supports it -- I think you define a sequence and then tell each table to use that sequence.
hvgotcodes
2010-08-04 16:12:40
Thanks hvgotcodes. Maybe I'll have Oracle someday!
2010-08-09 20:45:02