1

I use the simple entities below for exploring jpa-rs:

@Entity
public class Employee {

    @Id
    @GeneratedValue
    private int id;
    private String name;

    @OneToOne
    private Address address;
}

@Entity
public class Address {

    @Id
    @GeneratedValue
    private int id;
    private String street;
    private String city;

    @OneToOne(mappedBy = "address")
    private Employee employee;
}

Creating an Employee entity with an Address relation works like a charm:

{
  "name": "John Doe",
  "address": {
    "street": "Street No. 1",
    "city": "A City"
  }
}

But i cannot travers the resulting objects by the _links, like HATEOAS proposes.
The provided students example in the Eclipselink wiki (http://wiki.eclipse.org/EclipseLink/Examples) allows this easily. As far as i understand, i should be able to do the following:

  1. fetch the employee with id 1: GET url/entity/Employee/1:
    {
    "id": 1,
    "name": "John Doe",
    "_relationships": [
    {
      "_link": {
        "href": "url/entity/Employee/1/address",
        "rel": "address"
      }
    }
    ],
    "address": {
    "_link": {
      "href": "url/entity/Address/2",
      "method": "GET",
      "rel": "self"
    }
    },
    "staff": []
    }
  2. fetch the address of the employee: GET url/entity/Address/2:
    {
    "city": "A City",
    "id": 2,
    "street": "Street No. 1",
    "_relationships": [
    {
      "_link": {
        "href": "url/entity/Address/2/employee",
        "rel": "employee"
      }
    }
    ]
    }
  3. Now lets get back to the employee from here: GET url/entity/Address/2/employee -> http status 400

In the mentioned example i can flawlessly navigate using all the links for the relationship.

p.s.: I'd like to tag this JPA-RS, but i don't have enough reputation to create a new tag.

Imperative
  • 3,138
  • 2
  • 25
  • 40
  • 1
    @have created the jpa-rs tag. However I am not familiar with it, and I do not have the required 20k rep to edit teh wiki, so lets be patient :) – kostja Dec 05 '13 at 14:31

0 Answers0