Query with jpa + Hibernate with more than one idt in clause

Asked

Viewed 52 times

1

with Hibernate I can make an inquiry by idt as follows:

entityManager.find(Empresa.class, idtEmpresa);

And that would already return the mapped object of the company class, but what if I wanted to consult more than one idt, how would it look ?

for example, if I pass a String:

String idtEmpresa = "1,2,3";

The question is, How do I query with multiple Idts ?

1 answer

0

Hibernate 5 or higher supports multi-load:

Session session = entityManager.unwrap(Session.class);    
MultiIdentifierLoadAccess<PersonEntity> multiLoadAccess = session.byMultipleIds(Empresa.class);
List<Empresa> empresas = multiLoadAccess.multiLoad(1, 2, 3);

For more details and other options take a look at Thoughts on Java - How to fetch Multiple entities by id with Hibernate 5

Browser other questions tagged

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