How to make a query per ID in HQL using the LIKE operator?

Asked

Viewed 113 times

1

How do I make this consultation in HQL?

select * from entidadeQualquer where  id::text like '%12';

I tried the code below but it didn’t work:

select c from entidadeQualquerc  where  c.id like '%12';

2 answers

1


Without the entity code you can’t be sure, but you can try something like this:

String hql = "select c from entidadeQualquer c where CAST(id as text) like :id";

And to set the parameter:

Query query = em.createQuery(hql);
query.setParameter("id", "%12");
List<EntidadeQualquer> lista = query.getResultList()

1

For me, it worked like this:

String sql = "select t from Tabela t where str(t.id) like :id";

parameter:

query.setParameter("id", "%" + parteDoIdPassadoComoParametro + "%");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.