ObjectDB ObjectDB

Issue #1013: @FetchGroup in JPA similar to JDO

Type: Feature RequestPriority: NormalStatus: ActiveReplies: 0

I was checking what's new in different JPA implementation on the market and found quite interesting two features. First of those features is described in this ticket. It's similar to FetchGroup from JDO.

It works like this. First you specify attributes to fetch from database:

@FetchGroup(name="names", attributes={

public class Entity() {
    String firstName;
    String lastName;

then when running query you specify as a hint that this query should return Entities with only those fields filled with data:

TypedQuery query = em.createQuery("SELECT e FROM Entity e", Entity.class);
query.setHint(QueryHints.FETCH_GROUP_NAME, "names");

This will be equivalent to query using tuples:

TypedQuery<Tuple> query = em.createQuery("select e.firstName, e.lastName FROM Entity e", Tuple.class);

But with fetch group you don't have to convert tuples to objects.

I know that you can add many constructors to Entity and change query to

TypedQuery<Entity> query = em.createQuery("select new Entity(e.firstName, e.lastName) FROM Entity e", Entity.class);

but I think solution with fetch groups is much more readable and elastic. 



To post on this website please sign in.