O'Reilly logo

IBM WebSphere eXtreme Scale 6 by Anthony Chaves

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Query API

Storing Entity objects with the EntityManager API gives us a convenient way to store objects with relationships. You may have noticed that we are somewhat limited in how we find Entities if we rely on the EntityManager interface. The find method only accepts a primary key to search for in our objects. What if we don't know the primary key of the object or objects we want to find? We turn to the Query interface. The Query interface gives us a way to search an ObjectGrid instance using an SQL-like language to find managed entities that meet certain criteria.

Our first work with Query will be very simple:

private void queryBatch() { Query query = em.createQuery("select b.name from Batch b"); String batchName = (String)query.getSingleResult(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required