0

I've got a custom ID generator for a class. When I create a new instance of this class and saves it to the database using .save(), and which point is the ID actually generated? Is the generation delayed until the transaction is comitted, or will it be generated when i invoke .save() ?

sbrattla
  • 5,274
  • 3
  • 39
  • 63

1 Answers1

2

the id is generated on the save.

if you are within a transaction you have two options a commit or rollback

Mark Bakker
  • 1,278
  • 8
  • 19
  • Alright, so within the transaction, if I run the instance through save then that instance will receive an ID, right? Furthermore (different, but slightly related), I understand that versioning will be applied at flush/commit. Would you happen to know if this is right? – sbrattla Jul 12 '12 at 13:43
  • Consider the following: clients A and B load the same record R. After a time A commits back R with data changed, and after a while B commits too .. changing data of R - but not from the state of R after commit A. Automatic versioning does the following: a field is used to version the row data. In the above scenario A and B obtain the record R with version t. After the commit A the version is changed, so when B tries to commit the check upon the version fails. – Mark Bakker Jul 12 '12 at 13:49