Another, I think important, information about the same problem,
the children fields doesn't show up even in the admin console.

I'm posting here my code so that everyone could check it out.

---------- Parent Class -----------
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements IsSerializable {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;

    @Persistent
    private String userId;

    @Persistent(embedded="true", defaultFetchGroup="true")
    private Stat stat;

    public User() {}

    public String getEncodedKey() {
        return this.encodedKey;
    }

    public void setEncodedKey(String encodedKey) {
        this.encodedKey = encodedKey;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return userId;
    }
   
    public Stat getStat() {
        return stat;
    }

    public void setStat(Stat stat) {
        this.stat = stat;
    }

}

-------- Child Class --------
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Stat implements GeneralStat {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;

    @Persistent(mappedBy = "stat")
    private User user;   

    @Persistent
    private String userId;

    public Stat() {}
   
    public String getEncodedKey() {
        return encodedKey;
    }

    public void setEncodedKey(String encodedKey) {
        this.encodedKey = encodedKey;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    } 
}  

--------- Code Snippet not working ----------
PersistenceManager pm = PMF.get().getPersistenceManager();
String userId = "test";
Key userKey = KeyFactory.createKey(User.class.getSimpleName(), userId);
String userEncodedKey = KeyFactory.keyToString(userKey);
User user = new User();
user.setUserId(userId);
user.setEncodedKey(userEncodedKey);
String statEncodedKey = KeyFactory.keyToString(userKey.getChild(Stat.class.getSimpleName(), userId));
Stat stat = new Stat();
stat.setUserId(userId);
stat.setEncodedKey(statEncodedKey);
user.setStat(stat);
pm.makePersistent(stat);
pm.makePersistent(user);
pm.close();
       
pm = PMF.get().getPersistenceManager();
       
user = pm.getObjectById(User.class, userEncodedKey);
Stat stat = user.getStat();
-------------------------------------


I think I'm doing a very basic thing: persist a one-to-one bidirectional relationship.

Am I doing something wrong??

I can't really get it work...
Please help..!!

Thanks


patrizio.munzi wrote:
Hi,

I'm having the same problem...

When I try to fetch an object all its children fields are null.
I tried to set defaultFetchGroup = "true" but nothing changed...

Is there any work around for this???

I wouldn't want to pass to an unowned relationship...

Thanks

On Sep 16, 11:35 pm, "Jason (Google)" <[email protected]> wrote:
  
Hi bysse. You only need to create custom indexes for composite queries, i.e.
queries with two or more sort orders or queries with an equality filter on
one property and an inequality filter on another. All single-property
indexes are created by App Engine automatically, aside from Text and Blob
fields and fields you explicitly mark as unindexed.

I started seeing the same warning myself, although the end result was
exactly what I wanted. This seems to only affect owned relationships -- if
you're storing a Blob field or any other binary data, you should be able to
continue using the defaultFetchGroup parameter; I'll have to follow up to
see if there are any consequences to using this for owned relationships
given that the datastore is returning the correct result. You can also nix
the parameter and call something like getItemValues() before you close the
PersistenceManager, which will also give the intended result without the
warning.

- Jason

On Mon, Sep 14, 2009 at 12:01 PM, bysse <[email protected]> wrote:

    
I'm having the same problem.
If i understand this correctly i must create an index for all fields
in an entity. Otherwise it will be null when i fetch the entity?
      
If i set defaultFetchGroup = "true" i get this message which doesn't
look promising:
      
8:55:05,144 WARN  [DataNucleus.MetaData] - Meta-data warning for
Item.values: The datastore does not support joins and therefore cannot
honor requests to place child objects in the default fetch group.  The
field will be fetched lazily on first access.  You can modify this
warning by setting the datanucleus.appengine.ignorableMetaDataBehavior
property in your config.  A value of NONE will silence the warning.  A
value of ERROR will turn the warning into an exception.
      
Should i just set this property and ignore the warning?
      
/Erik
      
On Sep 8, 8:56 pm, "Jason (Google)" <[email protected]> wrote:
      
Hi David. I believe this is expected behavior -- unindexed properties,
including Text, Blob, and reference properties as well as descendants
(PrivilegedUser in this case) are not retrieved by default. There is an
easier way to add a field to the default fetch group:
        
@Persistent(defaultFetchGroup = "true")
private PrivilegedUser privilegedUser;
        
Can you let me know if this works for you? If not, can you share your
PrivilegedUser class definition?
        
- Jason
        
On Fri, Sep 4, 2009 at 9:56 PM, David <[email protected]> wrote:
        
I’ve been working with a fairly simple data model that has an
Organization object which contains some String members as well as a
member variable of type PrivilegedUser.  And PrivilegedUser extends a
User, and contains only a Key and some String members.
          
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable="true")
public class Organization implements Serializable {
          
      �...@primarykey
  �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
       private Long id;
          
      �...@persistent
   private String organizationId;
          
  �...@persistent
   private String organizationName;
          
  �...@persistent
    private PrivilegedUser privilegedUser;
          
….
          
I have code running successfully under 1.2.2 which creates an
Organization, then creates a Privileged User object, and assigns it to
the Organization, and then makes the Organization persistent.
Later I query by organizationId to retrieve the Organization object,
and update the PrivilegedUser on the Organization object.
This works fine under 1.2.2.
          
Under 1.2.5 I began getting the following error:
You have just attempted to access field "privilegedUser" yet this
field was not detached when you detached the object. Either dont
access this field, or detach it when detaching the object.
          
However, after stepping through the debugger I believe the root cause
is that the privilegedUser field is null on the Organization object
returned from the query (the String members are still correct).  This
value is null even before I attempt to detach the Organization object
from the PersistenceManager.
          
After seeing this behavior I modified the query code I had been using
to include a custom fetch plan for the query.
This did not change the behavior under 1.2.5.
          
              PersistenceManager pm = PMF.get().getPersistenceManager
();
          
               FetchGroup fetchGroup =
          
pm.getFetchGroup(Organization.class,
      
"OrganizationGroup");
               fetchGroup.addMember("privilegedUser");
          
               // Add this group to the fetch plan (using its name)
               FetchPlan fetchPlan = pm.getFetchPlan();
               fetchPlan.addGroup("OrganizationGroup");
          
               Query query = pm.newQuery(Organization.class);
               query.setFilter("organizationId == rhsValue");
               query.declareParameters("String rhsValue");
          
I don't think the following is relevant, but I’ve also noticed that
under 1.2.5 the following exception occurs, which has been reported by
others:
          
INFO: Failed to start reference finalizer thread. Reference cleanup
will only occur when new references are
created.java.lang.reflect.InvocationTargetException
          
Does this sound like a bug introduced under 1.2.5, or is this expected
behavior that was not enforced under 1.2.2?  In either case, does
anyone have a suggestion on how to work around this issue?
          
Thanks,
David
          
    


  

--

Patrizio Munzi
Product Specialist
Viale Bruno Buozzi, 19 - 00197 Roma (Italy)
tel: +39 06 4543 3540
fax: +39 06 4543 3587
mobile: +39 393 7195 164
mail: [email protected]
web: http://www.eris4.com
skype: eris4_munzi


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to