Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:21:17+00:00 2026-05-15T06:21:17+00:00

I am trying to persist Java objects to the GAE datastore. I am not

  • 0

I am trying to persist Java objects to the GAE datastore.

I am not sure as to how to persist object having (“non-trivial”) referenced object.
That is, assume I have the following.

public class Father {
    String name;
    int age;
    Vector<Child> offsprings; //this is what I call "non-trivial" reference 
    //ctor, getters, setters...
}

public class Child {
    String name;
    int age;
    Father father; //this is what I call "non-trivial" reference 
    //ctor, getters, setters...
}

The name field is unique in each type domain, and is considered a Primary-Key.

In order to persist the “trivial” (String, int) fields, all I need is to add the correct annotation. So far so good.
However, I don’t understand how should I persist the home-brewed (Child, Father) types referenced.
Should I:

  1. Convert each such reference to hold the Primary-Key (a name String, in this example) instead of the “actual” object, so Vector<Child> offsprings; becomes Vector<String> offspringsNames;?

    If that is the case, how do I handle the object at run-time? Do I just query for the Primary-Key from Class.getName, to retrieve the refrenced objects?

  2. Convert each such reference to hold the actual Key provided to me by the Datastore upon the proper put() operation? That is, Vector<Child> offsprings; becomes Vector<Key> offspringsHashKeys;?

I have read all the offical relevant GAE docs/example. Throughout, they always persist “trivial” references, natively supported by the Datastore (e.g. in the Guestbook example, only Strings, and Longs).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:21:18+00:00Added an answer on May 15, 2026 at 6:21 am
    • Please see google appengine docs following sections for more clear understanding (Relationships, Transactions)

    • Also read about detachable objects in JDO

    • For querying selective columns (or fields), read about fetchgroups in JDO

    For your question You have several options:

    • Owned One to many relationship (the objects will be in same entity group) Here you can have a list of Child in your parent (Father class). This will place all objects in the same entity group. If you do not want to fetch the children every time you fetch Father, you can remove the children from the “default fetch group”

    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
    public class Father {
       @PrimaryKey
       @Persistent
       private String name;
    
       @Persistent
       private int age;
    
       @Persistent(mappedBy = "father", defaultFetchGroup = "false")
       private List childern;
    }
    
    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
    public class Child   {
       @Persistent
       @PrimaryKey
       private String name;
    
       @Persistent
       private Father dad;
    }
    

    • Unowned relationships where you store the keys instead of references:

    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
    public class Father {
    
       @PrimaryKey
       @Persistent
       private String name;
    
       @Persistent
       private int age;
    
       @Persistent
       private List childern;
    }
    
    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
    public class Child   {
       @Persistent
       @PrimaryKey
       private String name;
    
       @Persistent
       private Key dad;
    }
    

    In this case you will have to manage the referential integrity and also make sure they are in the same entity group if you have to update/add them in a single transaction

    IMO, if I were modeling a real-world (Father-children) scenario, I’d go the “Owned relatinship” route, since, really, how many children a guy can have ;). Of course there is an additional question of how many fathers are you going to update at a time?

    Hope this helps, cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to persist a Template object in the app's database. It's not
I am getting below error whilst trying to persist an object that has a
I am trying to persist an object into the database. This operation should touch
I'm trying to persist my object but when I look in the dev console,
I am trying to persist a string object in Mysql(5.0.67) using hibernate. My entity
I have an object Instance with another object Course inside. When trying to persist
I am trying to develop a piece of code in Java, that will be
I'm trying to persist a set of what I would call relatively simple objects
I am trying to create an Entity manager to persist a object. Here is
I am trying to persist a one (Owner) to many (Car) relation with morphia(0.99)/mongoDB(2).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.