DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Andy Jefferson
Reporter: Giancarlo Dessena
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus API REST

Exception when trying to add SubClass Data over REST API

Created: 11/Jul/11 12:01 PM   Updated: 30/Apr/12 12:02 PM   Resolved: 11/Jul/11 02:26 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 3.0.0.release

- Datanucleus 2.2.3 + REST API
- Tomcat 6.0
- Windows XP

Datastore: MySQL

 Description  « Hide
I have set up the following class-model
public class SuperClass {
        private long id;
        private String name;

        /* getters/setters*/

public class SubClass extends SuperClass{
        private String additionalProperty;
        /* getters/setters*/

with the following metadata file
       <class name="SuperClass">
            <datastore-identity strategy="increment"/>
            <inheritance strategy="new-table">
               <discriminator strategy="class-name"/>
                  <column name="MY_PK_COLUMN"/>
        <class name="SubClass">
            <inheritance strategy="new-table">
                    <column name="MYSUB_PK_COLUMN" target="MY_PK_COLUMN"/>
            <field name="additionalProperty"

I can add elements of the SuperClass with the REST API
POST http://localhost:8080/dashboard_2/dn/com.corp.dashboard.jdo.SuperClass {"name":"test"}
HTTP/1.1 201 Created

But when it comes to adding elements of the SubClass I get an exception
POST http://localhost:8080/dashboard_2/dn/com.corp.dashboard.jdo.SubClass {"additionalproperty":"test"}

SCHWERWIEGEND: Servlet.service() for servlet DataNucleus threw exception
        at com.corp.dashboard.jdo.SuperClass.jdoReplaceField(
        at com.corp.dashboard.jdo.SubClass.jdoReplaceField(
        at com.corp.dashboard.jdo.SuperClass.jdoReplaceFields(
        at javax.servlet.http.HttpServlet.service(
        at javax.servlet.http.HttpServlet.service(
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(
        at org.apache.catalina.core.StandardWrapperValve.invoke(
        at org.apache.catalina.core.StandardContextValve.invoke(
        at org.apache.catalina.core.StandardHostValve.invoke(
        at org.apache.catalina.valves.ErrorReportValve.invoke(
        at org.apache.catalina.core.StandardEngineValve.invoke(
        at org.apache.catalina.connector.CoyoteAdapter.service(
        at org.apache.coyote.http11.Http11Processor.process(
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
        at Source)

Sort Order: Ascending order - Click to sort in descending order
Giancarlo Dessena added a comment - 11/Jul/11 01:00 PM

In all fetch methods resolving the field-name is done expecting the relative position of the field in the current Class.

but when posting/putting a new Object, the servlet uses absolute field positioning,
       int[] fieldNumbers = cmd.getAllMemberPositions(); /*returns absolute field numbers*/
       sm1.replaceFields(fieldNumbers, new LocalFieldManager(jsonobj, null, cmd, pm));
which results in errors when trying to fetch SuperClass fields.

In my case for example when I posted a SuperClass object there were no problems because the SuperClass had no parent class so relative indexing worked well.
But as soon as I posted a SubClass, there were errors when trying to retrieve the fields that were in the SuperClass, because the method getMetaDataForManagedMemberAtRelativePosition could only retrieve the metadata of the SubClass fields.

So I replaced all occourences of getMetaDataForManagedMemberAtRelativePosition with getMetaDataForManagedMemberAtAbsolutePosition and suddenly everything works out as expected.

POST http://localhost:8080/dashboard_2/dn/com.corp.dashboard.jdo.SubClass { name : "test for persistence", "additionalProperty" : "cool"}
HTTP/1.1 201 Created
  "additionalProperty" : "cool",
  "class" : "com.corp.dashboard.jdo.SubClass",
  "id" : "61",
  "name" : "test for persistence"

Andy Jefferson added a comment - 11/Jul/11 02:26 PM
Replaced the only call to that method. Untested since you don't provide a downloadable testcase as per the docs; left as an exercise to the raiser to test it

Giancarlo Dessena added a comment - 12/Jul/11 10:35 AM
Is a Test-War file ok?

Andy Jefferson added a comment - 12/Jul/11 10:46 AM
Not for me thanks. It's your responsibility to test it, available in nightly builds.

The DN problem reporting guide is very clear what is required if contributing tests, and you could easily follow our tests

Andy Jefferson added a comment - 12/Jul/11 10:55 AM
And please fix your email address, i'm sick of getting bounced mail messages

<>: Host or domain name not found. Name service
    error for type=A: Host found but no data record of
    requested type

Giancarlo Dessena added a comment - 12/Jul/11 12:07 PM
Ok. gonna check out the nightly builds
ps. email fixed