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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:30:02+00:00 2026-05-31T19:30:02+00:00

I am using DataNucleus’ implement of JDO on a local H2 database. I want

  • 0

I am using DataNucleus’ implement of JDO on a local H2 database. I want to check whether an object instance exists in the database knowing its key.

The object is defined as following:

@PersistenceCapable(objectIdClass=RawItemKey.class)
@Index(name="CONTAIN_IDX", members={"prefix", "language", "value"})
public class RawContainItem {

    @PrimaryKey
    @Column(length=40)
    String prefix = "";

    @PrimaryKey
    @Column(length=2)
    String language = "";

    @PrimaryKey
    @Column(length=Integer.MAX_VALUE)
    String value = "";    

    public RawContainItem(String prefix, String language, String value) {

        this.prefix = prefix;
        this.language = language;
        this.value = value;

    }

}

The Key class is:

public class RawItemKey implements Serializable {

    public String prefix = "";
    public String language = "";
    public String value = "";

    public static final char SEPARATOR = '\u2407';

    public RawItemKey() {

    }

    public RawItemKey(String retr) {

        int beg = retr.indexOf(SEPARATOR);
        int end = retr.lastIndexOf(SEPARATOR);

        if ( beg >= 0 ) {
            this.prefix = retr.substring(0, beg);
        }

        if ( end > 0 ) {
            this.value = retr.substring(end+1, retr.length());
        }

        if ( ( beg >= 0 ) && ( end > 0 ) ) {
            this.language = retr.substring(beg+1, end);
        }

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + (this.prefix != null ? this.prefix.hashCode() : 0);
        hash = 89 * hash + (this.language != null ? this.language.hashCode() : 0);
        hash = 89 * hash + (this.value != null ? this.value.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {

        if (obj == this) { return true; }
        if (obj == null) { return false; }

        if (getClass() != obj.getClass()) {
            return false;
        }

        final RawItemKey other = (RawItemKey) obj;

        if ((this.prefix == null) ? (other.prefix != null) : !this.prefix.equals(other.prefix)) {
            return false;
        }

        if ((this.language == null) ? (other.language != null) : !this.language.equals(other.language)) {
            return false;
        }

        if ((this.value == null) ? (other.value != null) : !this.value.equals(other.value)) {
            return false;
        }

        return true;

    }

    @Override
    public String toString () {

        return this.prefix + SEPARATOR + this.language + SEPARATOR + this.value;

    }    

}

The code I use:

RawItemKey tmp = new RawItemKey();
tmp.prefix = d.prefix;
tmp.language = "EN";
tmp.value = retr;
RawContainItem rretr = PM.getObjectById(RawContainItem.class, tmp);
if ( rretr == null ) {
    PM.makePersistent(new RawContainItem(d.prefix, "EN", retr));
}                                     

The error I get:

org.datanucleus.exceptions.NucleusUserException:
 Unable to create Object Identity for class "net.dwst.findword.DataNucleus.RawBeginItem"
 since key is of an unsupported type (net.dwst.findword.DataNucleus.RawItemKey)
    at org.datanucleus.ObjectManagerImpl.newObjectId(ObjectManagerImpl.java:3362)
    at org.datanucleus.api.jdo.JDOPersistenceManager.newObjectIdInstance(JDOPersistenceManager.java:1627)
    at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1749)
    at net.dwst.findword.EN.FeedDatabaseEN1.feed(FeedDatabaseEN1.java:92)
    at net.dwst.findword.EN.FeedDatabaseEN1.main(FeedDatabaseEN1.java:32)

What is causing this error and how to check whether the object exists in the database?

  • 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-31T19:30:03+00:00Added an answer on May 31, 2026 at 7:30 pm

    And is RawContainItem using single field identity ? Nope. Hint : read the javadocs of methods since they tell you when they are usable. If you have a “RawItemKey” then you have the “id”, so just use pm.getObjectById(id)

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

Sidebar

Related Questions

I am using DataNucleus's implementation of JDO on an H2 database instance opened in
I am using DataNucleus' implementation of JDO to populate a table on a local
I am using Datanucleus JDO on top of HSqlDb. I would like to execute
I am using Guice with JDO and Datanucleus in my desktop app. I am
Assuming one has an operational Java application using DataNucleus's implementation of JDO to access
I want to upload one image to the database by using Google app engine
I am using NeoDatis (DB4O is another similar Object DB) under DataNucleus. I see
I use ANT to run my JDO application example implemented using Datanucleus solution. When
I am using Datanucleus, JDO and Spring's declarative @Transactional management woven with Aspect-J. But
I am trying to follow the DataNucleus tutorial for JDO. I am using Maven

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.