JDO nested field not received on request

I am using the local version of the JDO implementation for App Engine. When I request an object that contains other objects as inline fields, inline fields are returned as null.

For example, let's say that this is the main object that I save:

@PersistenceCapable
public class Branch {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String name;

    @Persistent
    private Address address;

            ...
}

and this my embedded object:

@PersistenceCapable(embeddedOnly="true")
public class Address {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent
    private String street;

    @Persistent
    private String city;

            ...
}

The following code does not retrieve the embedded object:

    PersistenceManager pm = MyPersistenceManagerFactory.get().getPersistenceManager();

    Branch branch = null;
    try {
        branch = pm.getObjectById(Branch.class, branchId);
    }
    catch (JDOObjectNotFoundException onfe) {
        // not found
    }
    catch (Exception e) {
        // failed
    }
    finally {
        pm.close();
    }

Does anyone have a solution for this? How can I get a Branch object with my subaddress?

+5
source share
1 answer

, , . , , .

...

branch = pm.getObjectById(Branch.class, branchId);
pm.close();
branch.getAddress();  // this is null

branch = pm.getObjectById(Branch.class, branchId);
branch.getAddress();  // this is not null
pm.close();
branch.getAddress();  // neither is this

, :

Branch branch = null;
try {
    branch = pm.getObjectById(Branch.class, branchId);
    branch.getAddress();
}
catch (JDOObjectNotFoundException onfe) {
    // not found
}
catch (Exception e) {
    // failed
}
finally {
    pm.close();
}

:

pm.getFetchPlan().setGroup(FetchGroup.ALL);
branch = pm.getObjectById(Branch.class, branchId);
pm.close();
branch.getAddress();  // this is not null
+8

All Articles