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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:28:32+00:00 2026-05-15T01:28:32+00:00

java.lang.UnsupportedOperationException: This operation is not supported on Query Results at org.datanucleus.store.query.AbstractQueryResult.contains(AbstractQueryResult.java:250) at java.util.AbstractCollection.retainAll(AbstractCollection.java:369) at

  • 0
java.lang.UnsupportedOperationException: This operation is not supported on Query Results
    at org.datanucleus.store.query.AbstractQueryResult.contains(AbstractQueryResult.java:250)
    at java.util.AbstractCollection.retainAll(AbstractCollection.java:369)
    at namespace.MyServlet.doGet(MyServlet.java:101)

I’m attempting to take one list I retrieved from a datastore query, and keep only the results which are also in a list I retrieved from a list of keys. Both my lists are populated as expected, but I can’t seem to user retainAll on either one of them.

//           List<Data> listOne = new ArrayList(query.execute(theQuery));
//           DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
//           List<Data> listTwo = new ArrayList(ds.get(keys).values());
//           listOne.retainAll(listTwo);

EDIT

Ok, in an attempt to simplify, since this is apparently multiple problems in one, I have stopped using the low level API for datastore and instead of am just pulling one by one with a loop.

                List<MyClass> test = (List<MyClass>) query.execute();
                List<MyClass> test2 = new ArrayList<MyClass>();

                for (String key : favorites) {
                    test2.add(pm.getObjectById(MyClass.class, key));
                }

                log.info(test.toString());
                test.retainAll(test2);

The above works. It doesn’t throw the exception. The below does throw the exception. The only difference is the log.info. I’m stumped.

                List<MyClass> test = (List<MyClass>) query.execute();
                List<MyClass> test2 = new ArrayList<MyClass>();

                for (String key : favorites) {
                    test2.add(pm.getObjectById(MyClass.class, key));
                }

                test.retainAll(test2);
  • 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-15T01:28:33+00:00Added an answer on May 15, 2026 at 1:28 am

    It will not let me do new ArrayList() on the query result since it returns an array of objects.

    You however need to put them in a new ArrayList(). The returned List implementation apparently doesn’t support retainAll(). That’s what the exception is telling you.

    A “plain” ArrayList supports it. If passing through the ArrayList constructor is not possible due to difference in generic type, then you’ll need to manually loop over it and cast each item before adding.

    List<Data> listTwo = new ArrayList<Data>();
    for (Object object : ds.get(keys).values()) {
        listTwo.add((Data) object);
    }
    listOne.retainAll(listTwo);
    

    Update: as per your update, the entities are apparently lazily loaded/filled. Most ORM’s (DataNucleus is one) may indeed do that. As I don’t use DataNucleus, I can’t go in detail how to fix that in a “nice” way. But you at least now know the root cause of the problem and it can be solved the same way as above. Fill the list test in a loop as well.

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

Sidebar

Ask A Question

Stats

  • Questions 423k
  • Answers 423k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I am correct, this could be roughly translated to:… May 15, 2026 at 11:36 am
  • Editorial Team
    Editorial Team added an answer <input type="submit" value="Go" style="position:relative; top:25px; left: 50%;"> May 15, 2026 at 11:36 am
  • Editorial Team
    Editorial Team added an answer Updated (ht Andrew): use heroku's Bundler support create a Gemfile… May 15, 2026 at 11:36 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.