在hibernate中,是否有一种方法可以使包含id定义的抽象实体的每个子实体的段列值都不同,并且具有表\每\类继承?
我有两个从asbtract实体扩展而来的实体,如下所示:
@Entity
@GenericGenerator(name = "credentialIdGenerator",
strategy = "org.hibernate.id.enhanced.TableGenerator",
parameters = {
@org.hibernate.annotations.Parameter(name = "value_column_name", value = "GEN_VALUE"),
@org.hibernate.annotations.Parameter(name = "segment_column_name", value = "GEN_NAME"),
@org.hibernate.annotations.Parameter(name = "table_name", value = "CORE_CREDENTIAL_ID_GEN"),
@org.hibernate.annotations.Parameter(name = "prefer_entity_table_as_segment_value", value = "true"),
@org.hibernate.annotations.Parameter(name = "optimizer", value = "pooled-lo"),
@org.hibernate.annotations.Parameter(name = "initial_value", value = "50000"),
@org.hibernate.annotations.Parameter(name = "increment_size", value = "100")})
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Credential implements Serializable {
@Id
@GeneratedValue(generator = "credentialIdGenerator")
@Column(name = "ID")
private int id;
}
@Entity
@Table(name = "entity_a")
public class EntityA extends Credential { ... }
@Entity
@Table(name = "entity_b")
public class EntityB extends Credential { ... }
事实上,table_per_类继承策略是最适合我们数据库当前体系结构的策略,事实是目前没有办法创建新的表凭证。entitya和entityb是两个现有的表,有很多行,我需要凭证作为实体(而不是@mappedsuperclass),以便仍然能够拥有@onetomany关系。
当我必须保存这两个实体中的一个新实体时,预期的行为是在每个实体的core_credential_id_gen中有不同的行,一行用于entitya,另一行用于entityb,但结果只有一行带有凭证,如下所示:
+----+------------+-----------+
| id | GEN_NAME | GEN_VALUE |
+----+------------+-----------+
| 1 | Credential | 50099 |
+----+------------+-----------+
因此,有一种配置方法可以使此生成id表具有预期的行为?
谢谢你的帮助
(我的db环境是mariadb 10.3)
暂无答案!
目前还没有任何答案,快来回答吧!