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

1

With hibernate I can do a query by idt as follows:

entityManager.find(Empresa.class, idtEmpresa);

And this would already return the mapped object of the enterprise class, but what if I wanted to query more than one idt, what would it look like?

For example, if I pass a String:

String idtEmpresa = "1,2,3";

The question is, how do I query multiple idts?

    
asked by anonymous 22.10.2016 / 17:49

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 at a look at Thoughts on Java - How to fetch multiple entities by id with Hibernate 5

    
22.10.2016 / 18:40