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 _link
s, 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:
- 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": [] }
- 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" } } ] }
- 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.