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

  • Home
  • SEARCH
  • 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 307701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:34:57+00:00 2026-05-12T07:34:57+00:00

I have two classes in an owned one-to-many relationship. The parent is Map, and

  • 0

I have two classes in an owned one-to-many relationship. The parent is Map, and the child is POI (point of interest). I am trying to add a POI to an existing Map, but I get an exception when I try to persist my changes. Here are the two classes:

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

    @PrimaryKey
     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent(mappedBy = "map")
    private List<Poi> pois;

    public List<Poi> getPois() {
        return pois;
    }
}

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

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

    @Persistent
    private Map map;

    public Map getMap() {
        return map;
    }
    public void setMap(Map map) {
        this.map = map;
    }
}

And here is how I am trying to use them:

PersistenceManager pm = PMF.get().getPersistenceManager();

// create a new POI
Poi poi = new Poi();

// find the Map by its ID
Map map = pm.getObjectById(Map.class, Long.decode(mapId));

// add the POI to the map
map.getPois().add(poi);

// persist!
pm.makePersistent(map);
pm.close();

The line “map.getPois().add(poi);” throws an exception saying “java.lang.ClassCastException: java.lang.Long” but doesn’t tell me why. If I switch it around to “poi.SetMap(map);” it just fails silently. There is no error message and nothing happens.

Does anybody know how to correctly handle a one-to-many relationship in App Engine? Does anybody know of any good resources? Google’s documentation has been mildly helpful but it is really lacking.

  • 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-12T07:34:58+00:00Added an answer on May 12, 2026 at 7:34 am

    The first thing to check is that you are using version 1.2.2 of the sdk. Many fixes/enhancements were made to child/parent functionality in this release.
    One issue that was fixed sounds a lot like your issue, or at least related.

    If that doesn’t fix the problem, check that the class you are using the above code in is annotated @PersistenceAware, assuming it is not already @PersistenceCapable.

    If THAT doesn’t fix the problem, can you post the full class that is causing the problem (preferably cut down to the bare minimum of code that will reproduce the exception) In your excerpt for example, we don’t see the original map get created and saved, and don’t get to see where mapId comes from.

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

Sidebar

Related Questions

I have two classes: Parent and Child , mapped one-to-many with relationship owned by
I have two classes in a many-to-many relationship, but only one of them have
I have two classes with a parent-child relationship (the Parent class has-a Child class),
I have two classes in Grails application , Employee has hasMany(one To Many relations)
I have two classes, the Group class has a many to many relationship with
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, one that inherits from the other. The base class is
I have two classes set up as follows: class Point { protected: double coords[3];
I have two classes Teacher and Student . I am trying to get teacher
I have two classes, one nested in the other. Public Class Operation Public Property

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.