Hi!
Surrogate or natural keys is old discussion, but what about combined surrogate and natural strategy?
My intention is to simplify PK mapping to Hibernate mapping tool and cut-off java equals/hashCode methods implementation and so on....
according to Hibernate FAQ's, wiki, this forum..I read all these!
But I want to still be able to do maintenance on data in the database using pure and "simple" sql...
Creating simple FK to PK in the surrogate strategy will result in simple joins, but complex sql for data manipulation (to me, not Hibernate)
But, if I have PK's in surrogate style + natural keys in the form of a UNIQUE KEY, then in the sub-entities the integriy references the natural UK, not the surrogate PK, I cold agregate all advantages of these 2 strategies!
So I'm wondering if this is good pratice, but in the net, not much about this :(
Code:
---------------
| Entity A |
---------------
| |
| # id (pk) |
| # numA (uk) | ---------------
| # desc | | Entity C |
| date | ---------------
--------------- | |
| # id (pk) |
--------------- | # numA (fk to A->numA) | numA + numB combined to UK (Natural Key)
| Entity B | | # numB (fk to B->numB) | no one reference do A->id or B->id
--------------- | # text |
| | | date |
| # id (pk) | | etc |
| # numB (uk) | ---------------
| # desc |
| date |
---------------
What you find? What is the impact for hibernate mapping?