title: Eclipselink Batch vs fetch-join reading in Fetch Groups is this possible?
body: <p>I have a situation whereby I would like to create a query against an entity using EclipsLink JPA, I require 5 fields from this entity of which it has many. 2 of those fields are joined OneToMany relationships. I only require 2 primitive fields from each of the joins.</p>
  
  <p>What is the most efficient way to do this?</p>
  
  <p>I've considered a number of possiblities, batch reading seems the best bet based on what I have read however I believe this will only work if I retrieve the full entity i.e. SELECT a FROM Entity a... and the reason I don't want to do this is I have LOB and BLOB types that will eat dangerously into the memory.</p>
  
  <p>Join-fetch is another but the entity has ~10 joined tables and I don't want to duplicate all of this data.</p>
  
  <p>I have been using fetch groups (<a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/AttributeGroup" rel="nofollow">http://wiki.eclipse.org/EclipseLink/Examples/JPA/AttributeGroup</a>) and specifying the fields I want which causes cached lazing loading. This is workable and the memory footprint is better. The issue is though when I do entity.getCollection() it must do a single SQL statement for each call and this is where I feel it is inefficient. If I could do SELECT a.Field, a.Field2 from Entity A using some form of batching or join-fetching or better still apply this to my fetch group this would be best I would imagine but not sure if I could ensure that it would not load all related tables and only give me the ones I want.</p>
  
  <p>Help/thoughts would be much appreciated.</p>