我需要创建一个代表以下JPQL的条件查询:
我尝试指定RegraContrato类,但没有成功。
SELECT G FROM Grupo G JOIN G.regras R WHERE TYPE(R)= RegraContrato AND R.numeroContrato in(123)
@Entity
@Table(name = "GRUPO_ACESSO")
public class Grupo {
@OneToMany(mappedBy = "grupo",cascade = CascadeType.ALL,fetch = FetchType.EAGER,orphanRemoval = true)
private Set<Regra> regras = Sets.newHashSet();
}
@Entity
@Table(name = "REGRA_ACESSO")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Regra {
private static final long serialVersionUID = 5994730323053219858L;
@Id
@SequenceGenerator(name = "REGRA_ID_GENERATOR",sequenceName = "REGRA_SEQUENCE",allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "REGRA_ID_GENERATOR")
@Column(name = "ID")
private Long id;
}
@Entity
@PrimaryKeyJoinColumn(name = "ID")
@Table(name = "REGRA_CNPJ")
public class RegraCNPJ extends Regra {
@Column(name = "CNPJ")
private String cnpj;
}
@Entity
@PrimaryKeyJoinColumn(name = "ID")
@Table(name = "REGRA_CONTRATO")
public class RegraContrato extends Regra {
private static final long serialVersionUID = -2840125767126128182L;
@Column(name = "NUMERO_CONTRATO")
private Long numeroContrato;
}