Java继承关系的Hibernate映射

xiaoxiao2026-08-20  16

[b]Hibernate映射继承关系分三种:[/b] [b]1)每个类一张表:[/b] @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 用的不多 [b]2)每个类层次结构一张表:[/b] @Inheritance(strategy=InheritanceType.SINGLE_TABLE) 通过标识列来表明是哪一个子类 DiscriminatorColumn(name="type", discriminatorType = DiscriminatorType.STRING, length=30) 子类要加上:@DiscriminatorValue("") [b]3)子类有自己的表,但通过列关联到父表[/b] @Inheritance(strategy=InheritanceType.JOINED) 子类通过@PrimaryKeyJoinColumn()来表明用那一列来进行和父类的关联. 查询的时候该列为查询主键. [i]缺省值是InheritanceType.SINGLE_TABLE[/i] [i]http://whitesock.iteye.com/blog/173543[/i]
转载请注明原文地址: https://www.6miu.com/read-5051540.html

最新回复(0)