我的Java EE项目在WildFly 8上运行,并且正在使用JPA 2.1。 有一个Entity Person,一个抽象的Entity AbstractMatch和两个实现AbstractMatch的实体:FootballMatch和HockeyMatch。
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Email
@NotNull
private String email;
@ManyToMany(targetEntity=FootballMatch.class)
private List<AbstractMatch> matches
}
@MappedSuperclass
public abstract class AbstractMatch implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
}
@Entity
public class FootballMatch extends AbstractMatchEntity {
}
Person与AbstractMatch有ManyToMany关系。 ManyToMany批注的targetEntity属性定义要加载的类类型。因此,如果我从数据库加载Person,则所有匹配将被转换为此类类型(在此示例中为FootballMatch)。如何加载原始类类型,该对象在持久化时具有该类型?