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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:48:31+00:00 2026-05-25T09:48:31+00:00

I have just one week experience in GAE/Java and trying to port an legacy

  • 0

I have just one week experience in GAE/Java and trying to port an legacy application(developed using PHP/MySQL) to GAE+JDO. I’m now stuck with a basic issue in creating a relationship between two tables(kinds in GAE).

So here is the case:
We have a Users table which holds the user authentication information. It also has a field user_role which store role_id, which is actually a foreign key of another table user_roles.

From the the Entity-Relationship documentation in GAE, I understand that DataStore doesn’t support foreign-key relationships and designed the Users class by adapting the Employee-ContactInfo example in the docs.

When I executed the application, the user_roles kind is inserted each time I add an entry in Users table. The user_roles kind is supposed to have only three static values. But this is having redundant values as I input more records in Users.

I think that I’m missing something very trivial, but I couldn’t figure it out due to my inexperience to datastore. It would be very nice if someone could guide me to solve this issue.

Here is the code:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Users {

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

        @Persistent
        private String userName;

        @Persistent
        private String password;

        @Persistent
        private String salt;

        @Persistent
        private Date createdDate;

        @Persistent
        private Key createdBy;

        @Persistent
        private Date lastLogin;

        @Persistent
        private boolean status;

        @Persistent
        private String authKey;

        @Persistent(defaultFetchGroup="true")
        private SecurityRole securityRole;

        @Autowired
        SecurityRepository securityRepository ;

        public SecurityPrincipals(String userName, String password,SecurityRole securityRole,boolean status) {
                this.securityRole = securityRole;
                this.userName = userName;
                this.password = password;
                this.status = status;
        }

   //getters and setters
}

Definition for Roles:

@PersistenceCapable(detachable="true")
public class SecurityRole {

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

        @Persistent
        private String securityRoleName;

        @Persistent
        private String securityRoleDescription;

        @Persistent
        private String securityRoleStatus;

        @Persistent
        private Date securityRoleCreatedDate;

        public SecurityRole(String securityRoleName, String securityRoleDescription, String securityRoleStatus,String securityBaseType)
        {
                this.securityRoleName = securityRoleName;
                this.securityRoleDescription = securityRoleDescription;
                this.securityRoleStatus = securityRoleStatus;
                this.securityBaseType = securityBaseType;
        }
// getters and setters
}

The relevant code from Controller:

SecurityRole securityRole = securityRepository.getSecurityRole( securityRoleName);
users = new Users(userName,password,status,securityRole);
iUserRepository.save(employeeDetails);

Here is the definition of getSecurityRole:

public SecurityRole getSecurityRole(String securityRoleName)
        {
                      PersistenceManagerFactory pmf = this.jdoTemplate.getPersistenceManagerFactory();
                PersistenceManager pm = pmf.getPersistenceManager();
                try {
                        Query query = pm.newQuery( SecurityRole.class);
                        query.declareImports("import java.lang.String");
                        query.declareParameters("String securityRoleName");
                        query.setFilter("this.securityRoleName == securityRoleName");
                        List<SecurityRole> securityRoles = (List<SecurityRole>)query.execute(new String(securityRoleName));
                        SecurityRole temp = null;
                        for(SecurityRole securityRole: securityRoles)
                        {
                                temp = securityRole;
                        }
            return temp;
                }
                finally {
                        pm.close();
                }
        }

Here is the definition of iUserRepository.save():

public void save(Users user) {
               jdoTemplate.makePersistent(companyDetails);
}
  • 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-25T09:48:32+00:00Added an answer on May 25, 2026 at 9:48 am

    In the Users class, you have the defined the property

    @Persistent(defaultFetchGroup="true")
    private SecurityRole securityRole;
    

    This statement creates an “owned” relationship in GAE datastore, which means that when you create an object of the Users class, an object of the SecurityRole class will be created as well.

    What you need, is an unowned relationship that can be created as follows:

    @Persistent(defaultFetchGroup="true")
    private Key securityRole;
    

    In this way, a SecurityRole object is not created each time you create an instance of the Users class. For more information about owned and unowned relationships, take a look at http://code.google.com/appengine/docs/java/datastore/jdo/relationships.html

    Hope this helps!

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

Sidebar

Related Questions

I have web application written in java using Eclipse. It has just one servlet
i have a really basic java program just one .java/.class file (.java uncompiled .class
I've just begun learning Silverlight (though I have 3 years C# experience). I'm trying
I have just started YII one week back. I have made a theme in
We have a web-based application, backed by a MySQL database. One part of the
I'm using Rob Monies 'Jquery Week Calendar' to build a calendar application. I have
I have just one cs file in my repository which Git seems to think
With my database upgrade scripts, I typically just have one long script that makes
I have just updated to Snow Leopard and one of my important Flash files
I have a Web Service with Just one Web Method that returns a boolean

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.