0

I have a few JPA entities, Container and Thing. Container has a Thing field.

Asking for /container/123 will return the object container with id 123, and two links: _self = localhost/container/123 and thing = localhost/container/123/thing

However, when clicking on localhost/container/123/thing, the _self link for that thing will always be localhost/thing/0, which is wrong (the id should be something like 456, but it's always 0)

Am I doing something wrong, or is this just a bug in Spring Data / REST / HATEOAS?

Edu Garcia
  • 453
  • 7
  • 21
  • This seems related to JPA LAZY fetching. If I mark `thing` to be `EAGER`ly fetched, everything works properly, but I don't think that's the proper solution... – Edu Garcia Jun 08 '15 at 11:11
  • Can you show some of your code? How are you creating the links? – woemler Jun 08 '15 at 16:39
  • I'll add some code later, but it's just a normal CrudRepository, and the REST resource gets created automatically by Spring Data. Same for the links, I'm not creating them, they get created automatically – Edu Garcia Jun 08 '15 at 21:23
  • That is your issue then. The automatic link generation probably uses `EntityLinks`, which will point to the `findOne()` method for your `thing` controller. You are either going to have to manually create the links and/or override the default `ResourceAssembler` implementation being used. – woemler Jun 09 '15 at 00:59

0 Answers0