【发布时间】:2016-09-24 11:07:56
【问题描述】:
我有一个基实体类BaseDictionary:
@Entity
@Inheritance
public abstract class BaseDictionary {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@Column(name = "code")
protected String code;
@Column(name = "is_enabled")
protected Boolean enabled = true;
}
任何子类
@Entity
@Table(name = DB.DIC_RIGHTS_TYPE, schema = DB.SCHEMA_DIC)
public class DicRightsType extends BaseDictionary {}
@Entity
@Table(name = DB.DIC_ROLES_TYPE, schema = DB.SCHEMA_DIC)
public class DicRolesType extends BaseDictionary {}
有很多这样的子类。
给定一个像DicRightsType 这样的实体类名称,我想从与该名称的实体关联的表中获取数据。怎么可能实现?
我想像这样使用 JPA 存储库:Using generics in Spring Data JPA repositories 但这不适合我的情况,因为我在运行时只有实体类的名称,并且不知道如何为该类创建动态存储库。
【问题讨论】: