openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Grassel <>
Subject Fetch Groups
Date Mon, 13 Aug 2007 19:26:00 GMT
Hello, I'm writing a program that is trying to capitalize on FetchGroups, but I'm hitting some
behavior that I was not expecting, based on what I read from the manual.

I have two entities, Employee and Address, as follows:

        @FetchGroup(name="DescFetchGroup", attributes= {@FetchAttribute(name="description")}
        @FetchGroup(name="AddressFetchGroup", attributes= {@FetchAttribute(name="address")}
public class Employee {
    private int id;


    private String description;

    private Address address;




public class Address {
    private int id;
    private String street;
    private String city;
    private String state;
    private int zip;


public String toString()
        StringBuffer sb = new StringBuffer();
        sb.append(": street=").append(getStreet());
        sb.append(": city=").append(getCity());
        sb.append(": state=").append(getState());
        sb.append(": zip=").append(getZip());
        return new String(sb);

This is what I'm trying to do:

// ...
OpenJPAEntityManager oem = (OpenJPAEntityManager) em;

Employee emp = oem.find(Employee.class, 1);

if (emp.getDescription() != null)
  System.out.println("Employee description=" + emp.getDescription());
  System.out.println("Description is null");

if (emp.getAddress() != null)
  System.out.println("Employee address=" + emp.getAddress());
  System.out.println("Address is null");

// ...

I get the following results:

Employee description=Description 1
Employee address=Address(id=1): street=null: city=null: state=null: zip=0

It looks like an empty proxy object containing just the Address entity's primary key is returned.
 I was under the impression that with the AddressFetchGroup added to the fetch plan, that
the whole (Address) entity's persistent state would be eagerly loaded.

Is this a bug in OpenJPA, or is a proxy object supposed to be in the Address entity's place?

View raw message