FetchGroups do seem to be exactly what I'm looking for.  At any rate,
although I am able to successfully remove and add fetch groups from my
query, it doesn't seem to affect what data is populated.  I am running
OpenJPA 1.0.3 on JDK 1.5/5.0.  Can you take a peek and see if you see
anything obvious here?  Here's recent output from my simple test case:

Output:
[10/22/08 10:08:07:437 CDT] 0000005a SystemOut     O Before swapping fetch
groups:
[10/22/08 10:08:07:437 CDT] 0000005a SystemOut     O default
[10/22/08 10:08:07:437 CDT] 0000005a SystemOut     O After swapping fetch
groups:
[10/22/08 10:08:07:437 CDT] 0000005a SystemOut     O basic
[10/22/08 10:08:07:500 CDT] 0000005a SystemOut     O Name: Deleted
[10/22/08 10:08:07:500 CDT] 0000005a SystemOut     O Group Name: Statuses

As you can see, both the "groupName" property and "name" property contain a
value.  As you can see from my "basic" fetch group, name should not be
fetched.  Here is my code:

<code>
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("ProofOfConcept");
EntityManager em = emf.createEntityManager();

OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
OpenJPAQuery query = OpenJPAPersistence.cast(oem.createQuery("SELECT D FROM
DataItemBean D WHERE D.id=:id"));

System.out.println("Before swapping fetch groups:");
Collection groups = query.getFetchPlan().getFetchGroups();
Iterator iter = groups.iterator();
while(iter.hasNext()){
        Object o = iter.next();
        System.out.println(o);
}

query.getFetchPlan().removeFetchGroup("default");
query.getFetchPlan().addFetchGroup("basic");

System.out.println("After swapping fetch groups:");
groups = query.getFetchPlan().getFetchGroups();
iter = groups.iterator();
while(iter.hasNext()){
        Object o = iter.next();
        System.out.println(o);
}

java.util.List list = (java.util.List)query.setParameter("id", new
Integer(501))
        .getResultList();

for(int i = 0; i < 10 && i < list.size(); i++){
        DataItemBean dib = (DataItemBean)list.get(i);
        System.out.println("Name: " +dib.getName());
        System.out.println("Group Name: " +dib.getGroupName());
}

...

@Entity
@FetchGroups({
    @FetchGroup(name="basic", attributes={
        @FetchAttribute(name="id"),
        @FetchAttribute(name="groupName")
    })
})

@Table(name="DATA_ITEMS", schema="COMMON")
public class DataItemBean implements Serializable {
        
        @Column(name="ID")
        protected int id = 0;
        
        @Column(name="GROUP_NAME")
        protected String groupName = null;
        
        @Column(name="NAME")
        protected String name = null;

--getters and setters --
</code>

-- 
View this message in context: 
http://n2.nabble.com/Partial-populate-of-POJO-tp1356484p1364387.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to