Inheritance with Hibernate
I need some advice on modelling my开发者_开发知识库 data tables. I need to apply inheritance hierarchy on my tables using SQL Server and Hibernate. Could anyone show me a basic example? It could be a tutorial on website too.
Cheers...
Set up the tables so that the derived table shares primary key with base table.
MS SQL Server isn't an object-orientated database, it is a relational database. It sounds like you should be using views over your base tables rather than duplicating columns.
Duplicating columns is unnecessary and would no doubt impact performance and maintenance would become a nightmare.
Maybe edit your question to include more details on what you are trying to achieve.
Another way is to duplicate attributes in child tables and make parent table as VIEW (that selects by common attributes from all children).
CREATE VIEW Parent
AS
SELECT ID, Name FROM Child1
UNION ALL
SELECT ID, Name FROM Child2 ...
The problem could be with ID that should be unique through all the child tables (using GUIDs is preferrable)
精彩评论