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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:09:13+00:00 2026-05-31T18:09:13+00:00

I have the following issue: A java object contains two arrays of core datastore

  • 0

I have the following issue:

A java object contains two arrays of core datastore types (com.google.appengine.api.datastore.Text and java.util.Date), plus an int (for storing the current populated position in the arrays) and some other fields.

I believe the documentation states that arrays of core datatypes should be ok (cf. http://code.google.com/appengine/docs/java/datastore/jdo/dataclasses.html, under the “Class and Field Annotations”).

The object is updated using a method named “updateAnswer”. When this method is called, the object is indeed updated (the int is incremented and stored correctly), but the arrays never store anything but nulls.

I would greatly appreciate it if someone could point out where my mistake lies.

Here is the object (and its parent, for completeness):

@PersistenceCapable
public class TextualAnswer extends Answer {

    @Persistent
    private Text textAnswer;

    @Persistent
    private Date date;

    @Persistent
    private int pos;

    @Persistent
    private Text texts[];

    @Persistent
    private Date dates[];

    public TextualAnswer(Key question, Key user, Date date) {
        super(question, user, 0);
        this.textAnswer = null;
        this.date = date;
        pos = 0;
        texts = new Text[20];
        dates = new Date[20];
    }

    public String getTextAnswer() {
        return (textAnswer != null ? textAnswer.getValue() : null);
    }

    public Date getDate() {
        return date;
    }

    public void updateAnswer(String textAnswer, Date date) {
        if (texts.length == pos) { // expand?
            Text ttemp[] = texts;
            texts = new Text[pos * 2];
            System.arraycopy(ttemp, 0, texts, 0, pos);

            Date dtemp[] = dates;
            dates = new Date[pos * 2];
            System.arraycopy(dtemp, 0, dates, 0, pos);
        }
        texts[pos] = this.textAnswer;
        dates[pos] = this.date;
        pos++;

        this.textAnswer = (textAnswer != null ? new Text(textAnswer) : null);
        this.date = date;
    }
}

The parent:

@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Answer {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private Key question;

    @Persistent
     private Key user;

    @Persistent
    private double score;

    @Persistent
    private boolean last;

    @Persistent
    private Text comment;

    public Answer(Key question, Key user, double score) {
        this.question = question;
        this.user = user;
        this.score = score;
        last = false;
        comment = null;
    }

    public Key getKey() {
        return key;
    }

    public Key getQuestion() {
        return question;
    }

    public Key getUser() {
        return user;
    }

    public double getScore() {
        return score;
    }

    public boolean isLast() {
        return last;
    }

    public String getComment() {
        return comment != null ? comment.getValue() : null;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public void setLast(boolean last) {
        this.last = last;
    }

    public void setComment(String comment) {
        this.comment = comment != null ? new Text(comment) : null;
    }
}

A closing note. I realize I could use Lists etc instead, and if I do not figure this out that is indeed my backup plan. But, I would like to realize why this isn’t working, so I’d love any suggestions that I switch to objects instead of arrays to be accompanied with an explanation as to why the arrays are not working 😉 Thank you.

Ex animo, – Alexander Yngling

  • 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-31T18:09:14+00:00Added an answer on May 31, 2026 at 6:09 pm

    So, after some sleep it occurred to me… it’s an array index. I’m using JDO. I’m an idiot 😉

    I thought about deleting this question, but just in case someone else searches for this, here’s the problem:

    http://www.datanucleus.org/products/datanucleus/jdo/orm/arrays.html

    JDO cannot know that an array index has been updated, so you have to either set the field again, or use the following to tell JDO to update the database:

    JDOHelper.makeDirty(obj, "fieldName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following issue using java 1.4 I try to display a very
I'm just starting with Object Oriented PHP and I have the following issue: I
I have the following issue related to iterating over an associative array of strings
I have the following issue and I would like to know what exactly happens.
I have the following issue with a UTF8 files structured as following: FIELD1§FIELD2§FIELD3§FIELD4 Looking
I'm building a grid in ASP.NET MVC and I have the following issue: Above
Please help regarding the following issue. I have enabled the Block popup option in
I'm trying to adress the following issue: I have a server side .net application
I am having following issue with reading binary file in C. I have read
I'm designing a mySQL DB and I'm having the following issue: Say I have

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.