开发者

Inheritance with Hibernate

开发者 https://www.devze.com 2023-03-13 07:26 出处:网络
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

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.

Inheritance with Hibernate


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号