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 8951477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:40:22+00:00 2026-06-15T13:40:22+00:00

I’m getting my feet wet with persistence and Objectify. I’d like some guidance on

  • 0

I’m getting my feet wet with persistence and Objectify. I’d like some guidance on assigning a Parent key. My specific questions are in all caps. Thanks.
(The sample model below contains an AppUser and a Video. The idea is like YouTube; a user creates videos that belong to him/her.)

@Entity
class Video{
// QUESTION 1: SHOULD THIS CLASS HAVE ONLY 1 KEY FIELD IF I WANT A 
PARENT RELATIONSHIP WITH AppUser, AND TYPE IS Key<AppUser> ?
@Parent Key<AppUser> owner;
@Id private Long id;

protected Video(){}
protected Video(User u){ // GAE User object     
    AppUser au = ofy().load().type(AppUser.class).filter("userId",u.getUserId()).first().get();

    // QUESTION 2: WHICH WAY IS RIGHT (TO ASSIGN PARENT KEY)?
    this.owner = Key.create(au.getKey(),AppUser.class,au.getId()); 
    // or:
    // owner = au.getKey();
    // or:
    // owner = au;
}
}

@Entity
public class AppUser {
@Id private String userId;

// QUESTION 3: DO ALL CLASSES REQUIRE A KEY FIELD?
private Key<AppUser> key;

protected AppUser(){}
protected AppUser(User u){// GAE User object    
    this.userId = u.getUserId();
}

public String getId(){
    return userId;
}

public Key<AppUser> getKey(){
    // QUESTION 4: IS THIS THE CORRECT WAY TO RETURN THE KEY? 
    // WOULD THAT IMPLY I NEED TO EXPLICITLY ASSIGN A VALUE TO FIELD key?

    return this.key;

    // THE ALTERNATIVE WOULD BE TO CREATE A KEY 
AND RETURN IT RIGHT? (THEN I CAN EXCLUDE FIELD key?)
    // return Key.create(AppUser.class, userId);
}
}
  • 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-06-15T13:40:23+00:00Added an answer on June 15, 2026 at 1:40 pm

    Answering my own question based on further knowledge:

    1. Normally if a parent relationship is desired, one Key is fine. I can’t see why another Key field would be required.
    2. I don’t think there’s 1 right way to assign a value to the @Parent Key. Using this seems to work:

      this.parent = Key.create(instanceOfParent);

    3. All classes do not REQUIRE a key field. Use when needed.
    4. There’s no one right way to return a Key, both examples could work.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.