鉴别器公式 SQL

DiscriminatorFormula SQL

我有一个mappedSuperClass,我正在从中派生出具体的实现。获得 reportType.name 值以便能够将其添加到子实体的 SQL 是什么?

@MappedSuperclass
@Table(name = "report")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula("select reportType.name from Report")  //HQL ????
@DiscriminatorValue(not null)  // catches everything left over
public abstract class Report<E extends Exception> {

     @OneToOne(mappedby="id")
     private ReportType reportType
     ...
}

@Entity
@DiscriminatorValue(“credit”)
public class CreditScoreReport<E extends Exception> extends Report<E> {
   public void doCreditScoreStuff(){
      ...
   }
}

@Entity
@DiscriminatorValue(“DMV”)
public class DmvReport<E extends Exception> extends Report<E> {
   public void doDmvStuff(){
      ...
   }
}

@Entity
public class ReportType {
    @id
    private Long id;
    @Column(name="name")
    private String name;

    // mutators, etc
}

REPORT_TYPE TABLE ENTRIES
| id | name   |
---------------
| 1  | DMV    |
| 2  | CREDIT |
| 3  | HEALTH |

我最初写的可能有用。我所做的唯一更改是使 discriminatorFormula 原生 SQL