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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:29:02+00:00 2026-05-23T18:29:02+00:00

I am using google app engine and JDO. In one of my servlets i

  • 0

I am using google app engine and JDO. In one of my servlets i am adding objects in a linkedlist and saving everything using persistence manager. Till the end of servlet it shows that everything is working fine. it appends the linkedlist ok. But when i try to fetch that linkedlist from datastore by using jsp page, i figure out that only one object is added to that linkedlist. Rest of the objects which i added in linkedlist are not saved in datastore. Why is it happening?
Thanks in advance.
here is the code:

 public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {

  resp.setContentType("text/html");

  PersistenceManager pm = PMF.get().getPersistenceManager();
  try
  {
//.... 
    for(int j=0; j<coordinate.length; j++){
        if(j < locations.size()){
                locations.get(j).getCoordinate().setLatitude(coordinate[j].x);
                locations.get(j).getCoordinate().setLongitude(coordinate[j].y);                         
        }else{
                        loc.setLatitude(coordinate[j].x);
                        loc.setLongitude(coordinate[j].y);
                        locat.setCoordinate(loc);
                        locations.add(locat);
        }
                   System.out.println(locations.size());
    }
    }catch(Exception ex){
        System.out.println("Error fetching runs: " + ex);
    }final{
        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-23T18:29:02+00:00Added an answer on May 23, 2026 at 6:29 pm

    Your code is not complete, so it’s hard to be sure, but I suspect that you’re basically doing this:

    Location locat = new Location();
    List<Location> locations = ...;
    for (int j = 0; j < coordinate.length; j++) {
        // ...
        locat.setCoordinate(loc);
        locations.add(locat);
    }
    

    In Java, adding an object to a list doesn’t make a copy from the object into the list. The list simply stores a reference to your object. So, at each iteration, you overwrite what you stored in the object at the previous iteration, and add a new reference to the same object in the list. At the end, the list contains N references to the exact same object.

    So when the datastore stores the list in database, it notices that the list contains the same object duplicated n times, and only stored the object once.

    You thus have to make a new location object at each iteration:

    List<Location> locations = ...;
    for (int j = 0; j < coordinate.length; j++) {
        // ...
        Location locat = new Location();
        locat.setCoordinate(loc);
        locations.add(locat);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google App Engine with Google's JDO implementation to save an entity
I'm using JPA (not JDO) on Google App Engine and this is a typical
I'm building an application using Google App Engine. The application consists of several servlets,
To identify my JDO objects in Google App Engine I use the Key type.
I'm using the Google app engine and JDO. What is the best way to
Most of the docs for Google App Engine are written for JDO. Only one
I am trying to run grails on google app engine using JDO, but I
I'm currently porting some work from MySQL to Google App Engine/Java. I'm using JDO,
I am moving from PHP/MySQL to Google App Engine and using JDO as interface
I'm using Maven GAE plugin with JDO, I started with jappstart example (https://github.com/tleese22/google-app-engine-jappstart/blob/master/pom.xml), but

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.