Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store Key-Value pairs using JDO (datanucleus & appengine)
    primarykey
    data
    text
    <p>I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key being a strictly positive integer and value being a string):</p> <pre><code>import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.Persistent; import javax.jdo.annotations.PrimaryKey; @PersistenceCapable(detachable = "true") public final class ConfigurationProperty { @PrimaryKey @Persistent private Integer id; @Persistent private String value; public ConfigurationProperty(Integer id, String value) { this.id = id; this.setValue(value); } public Integer getId() { return this.id; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } } </code></pre> <p>As you can see, I'm defining a field "id" (which is the key of the key-value pair) and use it as the class's primary key.</p> <p>However, when I try to access an entry:</p> <pre><code>int searchId = 4; ConfigurationProperty property = this.persistence.getObjectById(ConfigurationProperty.class, searchId); </code></pre> <p>I get the exception:</p> <pre><code>javax.jdo.JDOFatalUserException: Received a request to find an object of type [mypackage].ConfigurationProperty identified by 4. This is not a valid representation of a primary key for an instance of [mypackage].ConfigurationProperty. NestedThrowables: org.datanucleus.exceptions.NucleusFatalUserException: Received a request to find an object of type [mypackage].ConfigurationProperty identified by 4. This is not a valid representation of a primary key for an instance of [mypackage].ConfigurationProperty.) </code></pre> <p>I'm almost sure I would not run into an exception should I create a separate field for the primary key and the pair's key, but that would create some form of redundancy and possibly performance issues, since the pair's key <em>is</em> unique.</p> <p>I also only get the exception on Google Appengine. When I tested the application using a Derby database, there were no problems.</p> <p>Thank you for any suggestion!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload