有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JPA/toplink异构实体列表

各位同事:, 使用JPA,我需要解决以下问题:在数据库级别存在3个实体(表示SuperEntity、DetailsAgentity和DetailsByEntity)。SuperEntity包含DetailsAgentity和DetailsAgentity字段的公共部分

所以问题是:是否有可能从JPA中解决混合元素detailsAgentity和detailsEntity的集合?是否可以在toplink中退出某些扩展以指定实体的类


共 (2) 个答案

  1. # 1 楼答案

    在标准JPA中,查询是多态的。以下是JPA 1.0规范中的相关章节:

    3.6.5 Polymorphic Queries

    By default, all queries are polymorphic. That is, the FROM clause of a query designates not only instances of the specific entity class(es) to which it explicitly refers, but subclasses as well. The instances returned by a query include instances of the subclasses that satisfy the query conditions.

    For example, the query

    select avg(e.salary) from Employee e where e.salary > 80000
    

    returns the average salary of all employees, including subtypes of Employee, such as Manager and Exempt.

    4.4.8 Polymorphism

    Java Persistence queries are automatically polymorphic. The FROM clause of a query designates not only instances of the specific entity class(es) to which explicitly refers but of subclasses as well. The instances returned by a query include instances of the subclasses that satisfy the query criteria.

    因此,默认情况下,对超类型的任何查询都会在结果中包含子类型

  2. # 2 楼答案

    假设SuperEntity被映射为继承树的根,那么该类型的查询结果可以返回其具体子类的异构集合