每个具体类的表行为的Hibernate表

时间:2015-10-08 04:18:06

标签: java hibernate inheritance

让我们说,我的课程employeeId包含字段namePermanentEmployee。这是由另一个类salary继承的,其中包含字段experience@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)。我使用employeeId。从这里我明白它会创建两个表。一个用于父类,包含两列namename。具有四列的子类的另一个表。这是employeeidsalaryexperience@OneToOne
当我尝试使用所有四个值保留子对象(永久员工)时,它正在插入在子表中。 仅限子表。它没有插入父表。
[1]这是默认行为吗?还是我错过了什么?我需要像@Inheritance(strategy = InheritanceType.JOINED)映射这样的实体关系吗? [旁注]我也试过11:07:51 [Apache] Apache Service detected with wrong path 11:07:51 [Apache] Change XAMPP Apache and Control Panel settings or 11:07:51 [Apache] Uninstall/disable the other service manually first 11:07:51 [Apache] Found Path:"D:\file3\install\xampp1\apache\bin\httpd.exe" -k runservice 11:07:51 [Apache] Expected Path: "c:\xampp1\apache\bin\httpd.exe" -k runservice 11:07:51 [mysql] MySQL Service detected with wrong path 11:07:51 [mysql] Change XAMPP MySQL and Control Panel settings or 11:07:51 [mysql] Uninstall/disable the other service manually first 11:07:51 [mysql] Found Path: D:\file3\install\xampp1\mysql\bin\mysqld.exe --defaults-file=d:\file3\install\xampp1\mysql\bin\my.ini mysql 11:07:51 [mysql] Expected Path: c:\xampp1\mysql\bin\mysqld.exe --defaults-file=c:\xampp1\mysql\bin\my.ini mysql 11:07:51 [main] Starting Check-Timer 11:07:51 [main] Control Panel Ready 。这次使用Table per subclass,它为它们创建了两个表和外键关系。并将其插入表中。

1 个答案:

答案 0 :(得分:0)

是的,如果您使用的是@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS),则该实体将被持久保存到单个表中,该表代表持久化实体的类。它可能对性能有好处,因为您在获取实体实例时不必进行表连接。但它也有缺点,例如,表没有规范化,层次结构中父级的修改会导致所有子表中的更改。在大多数情况下,这种策略并不是建议的,尽管它是最简单的策略。

至于OneToOne,如果你的意思是,你必须提供父类和它的子类之间的关系,那么没有。它用于在两个或多个实例之间建立关系,而不是用于类层次结构。

相关问题