2
Is there any way to pass as a parameter in a NamedQuery
the value of Enum
.
public enum TipoConta{
CREDITO("Cartao de Credito"), DEBITO("Cartao de Debito");
private final String descricao;
TipoConta(String descricao) {
this.descricao = descricao;
}
@Query("SELECT g FROM Gasto g WHERE g.transacao.tipo.nome = TipoConta.DEBITO.descricao")
List<Gasto> findAllGastos();
}
This is an example of what I would like to do, in my code I need to pass as a condition, and I pass a description. But I wouldn’t want to leave like hard code in Query
, and pass a constant of a Enum
, so I just change the Enum
and changes in all Query
.
In the bank is "Credit card" and "Debit card"?
– Fernando Leal
I tried to create an example of my problem because in the code is something else. But what I wanted to do is to pass as a condition the description of a ENUM, Like @Fernando passed, but that way error occurs in Eclipse.
– Danilo Fernandes