Hi,
this is just a "philosophical" question for the database gurus which inhabitate this forum.
Let's say I have an application which must be portable to different databases. My tables all have an auto-generated id as a primary key, and unique indexes on "business" keys. I found this practice as a suggested one often in Hibernate documentation.
Now, when I define a many-to-one it looks very simple and clever to use that primary key as the mapping key between parent and child tables.
But what happens if I must port the application to another database and I must export the already existing data ? The id fields are auto-generated and usually the database server doesn't like INSERTs which populate auto-generated keys. So I should let the DB regenerate the IDs. And the collections based on them would be all wrong then.
My solution is then to define <many-to-one> to map parent/child using the "business" keys (which can be multi-column). I don't really know if there's a better way to do this.
Any suggestions ?
Thanks in advance.
|