Next stop on the Annotatiomania™ Train: FetchGroups


Here’s how an Annotatiomaniac™ can optimise his second-level cached JPA queries conveniently by adding yet more annotations (what else?) to his simple and plain POJO’s. Remember that EJB 3.0 was about removing dependencies from javax.ejb.EJBObject, javax.ejb.EJBHome and similar interfaces? Well… check out this example:

import org.apache.openjpa.persistence.*;

@Entity
@FetchGroups({
    @FetchGroup(name="detail", attributes={
        @FetchAttribute(name="publisher"),
        @FetchAttribute(name="articles")
    }),
    ...
})
public class Magazine {

   @ManyToOne(fetch=FetchType.LAZY)
   @LoadFetchGroup("detail")
   private Publisher publisher;

   ...
}

Straightforward. But what does it do? Here’s the definition:

Fetch groups are sets of fields that load together. They can be used to to pool together associated fields in order to provide performance improvements over standard data fetching. Specifying fetch groups allows for tuning of lazy loading and eager fetching behavior.

I see. I can hear your DBA screaming at the indecipherable and out of control SQL that must result from all of that. Or can anyone show me an example where this does NOT go out of control? Here’s Fetch Groups, as documented by Oracle Fusion Middleware, a tool to simplify your life when working with JPA / JDO:

http://docs.oracle.com/cd/E16764_01/apirefs.1111/e13946/ref_guide_fetch.html

</rant>

One thought on “Next stop on the Annotatiomania™ Train: FetchGroups

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s