Hello, I have two questions about key generators: 1) why are they required? For example, SQL Server (and many other database engines) support auto-incrementing identity columns that are often used as primary keys. Why not just declare them as such instead of using this concept of a separate key generator table? 2) because key generator tables for a specific type are shared (I think the default should be to create separate tables following the 'TableName-Generator' naming pattern), if you want to create a separate generator you have to name it using the KeyGenerator attribute. Why does DO always append "_Generator" to the name specified instead of using the name as given? 99% of the time keys are just named "ID" and auto-increment from 1 (occasionally you have GUID columns needing NEWSEQUENTIALID()). I am wondering what kind of scenarios led to this concept of key generators in DO because they do seem to complicate matters. Thanks, Eric. |
Hello Eric, having separate key generator tables (or sequences if they are supported by the database) greatly simplifies pipeline. For example it becames possible to batch insert created objects because key values could be obtained before entities are saved to the database. Another example is referencing newly created entity, if identity column would be used directly such references would require update after changes are saved. Another important reason is the ability to have persistent interfaces across hierarchies which requires objects in different hierarchies to have non-overlapping key values. In other words such hierarchies should have the same key generator. Special suffix is added to key generator tables to avoid naming conflicts with regular user tables. If you wanted to specifically use the same table for key generation, this will not work. Key generator tables have specific layout and handled specifically by DO: for example set of keys are fetched and cached in the |