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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:50:11+00:00 2026-05-15T20:50:11+00:00

I have two objects a user and a role which I make persistant using

  • 0

I have two objects a user and a role which I make persistant using JDO and googles app engine. The two datatypes are related to each other as unowned many to many relationship. I tried to model that much as in the gae-tutorial desribed as sets holding the key of the corresponding object. By the time I create my objects, those keys are null. So in order to get some keys generated I make those objects persistant. After that, I add the refering keys to those objects. However those keys are not getting stored in the end.

Beside setting the keys, I also manipulate some other attributes (after makePersistent). Those changes later are reflected in the datastore. However, all the key changes I make after makePersistent, do not make it to the datastore. If I set those keys before makePersistent, they get stored as they should. However, that is no solution, as at least one object must logically receive the key refrence after it was made persistant.

Below some sample code, to explain the issue.

What is good practice to store those keys?

Persistable Role class

public class Role {

   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   private Key Role_id;

   @Persistent
   private Set<Key> Users = new HashSet<Key>();
...
}

Persistable User class

public class User {

   @PrimaryKey
   @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
   private Key User_id;

   @Persistent
   private String EMail = null;

   @Persistent
   private Set<Key> Roles = new HashSet<Key>();
   ...
}

Code extract which creates 1 Role and 1 User and tries to set the key-references on both sides. They keys changs don’t end up in the datastore. However, the change on the email address is written to the data store.
…

    PersistenceManager pm = PMF.get().getPersistenceManager();
    Role GlobalAdmin = new Role();
    User Daniel = new User();

    try {
        pm.makePersistent(GlobalAdmin);
        pm.makePersistent(Daniel);
    } catch (Exception e){
        System.out.println("Storing failed: " + e.getMessage());
    }

    GlobalAdmin.addUser(Daniel.getUser_id());
    Daniel.addRole(GlobalAdmin.getRole_id());
    Daniel.setEMail("a@b.com");

    pm.close();
...
  • 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-15T20:50:11+00:00Added an answer on May 15, 2026 at 8:50 pm

    I found one solution to my problem. When I want to write those keys, I have to detach those objects and make them persistent again later. Neither I understand why I have to do that nor if there would be something more elegant. However, it proofs to work.

    So first of all those classes must be detechable:

      @PersistenceCapable(detachable = "true") 
      public class User {
      ...
    

    After making the objects persistant, I detach them, set my keys and reatch those objects to the store…

        ...
        pm.makePersistent(GlobalAdmin);
        pm.makePersistent(Daniel);
    
        pm.detachCopy(GlobalAdmin);
        pm.detachCopy(Daniel);
    
        GlobalAdmin.addUser(Daniel.getUser_id());
        Daniel.addRole(GlobalAdmin.getRole_id());
    
        pm.makePersistent(GlobalAdmin);
        pm.makePersistent(Daniel);
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my two classes User and Role , and I need to make
Let's say I have two objects: User and Race. class User attr_accessor :first_name attr_accessor
I have two models, Message and User. Message has two User objects, user_1 and
Suppose I have the following two objects: first_name_relation = User.where(:first_name => 'Tobias') # ActiveRecord::Relation
So I have two filtering objects. One is a drop down list, which chooses
Let's say I have a list of User objects with two properties...ID and Name
I have two objects: User and Client, both implements interface IMember interface IMember {
I have two models: Company and User they have a has_and_belongs_to_many relationship. I'm using
I have two MKCoordinateRegion objects. Based on values from those objects I make two
I have two relational tables: the Profiles table which contains 3 kinds of user

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.