java - Spring Data REST and IdClass - not compatible? -


i trying use spring data rest given sql schema, uses jpa @idclass annotation associative tables (intersection table, or many-to-many resolution table). these mapping entities not serialized properly.

i created small project, illustrates problem. it's fork of spring-data-examples, , pretty straightforward. using eclipselink, tested hibernate , problem same.

https://github.com/otrosien/spring-data-examples/tree/idclassfailurewithserializable

the setup: 2 entities: customer , relationship, 2 repositories: customerrepository, relationshiprepository, both extend crudrepository

customer has generated id, , firstname, lastname string. relationship has idclass "relationshipid" , customer1, customer2 composite primary key, both having foreign key on customer. plus relation string.

a basic integration test shows entities work expected.

customer dave = customers.save(new customer("dave", "matthews")); customer jack = customers.save(new customer("jack", "johnson"));  assertthat(customers.findone(dave.getid()), is(dave)); assertthat(customers.findone(jack.getid()), is(jack));  relationship rel = relationships.save(new relationship(dave, jack, "likes")); assertthat(relationships.findone(rel.pk()), is(rel)); 

so far good. let's try via rest api now.

post http://localhost:8080/customers content-type: application/json  {   "lastname" :"dave",   "firstname":"matthews" }  post http://localhost:8080/customers content-type: application/json  {   "lastname" :"jack",   "firstname":"johnson" }  post http://localhost:8080/relationships content-type: application/json  {   "customer1" : "http://localhost:8080/customers/1",   "customer2" : "http://localhost:8080/customers/2",   "relation" : "likes" } 

i 201 created, good. representation of mapping entity looks broken. instead of proper links seem serialized objects.

get /relationships  200 ok {   "_embedded" : {     "relationships" : [ {       "relation" : "likes",       "_links" : {         "self" : {           "href" : "http://localhost:8080/relationships/customer%20%5bid=2,%20firstname=f,%20lastname=l%5d"         },         "customer1" : {           "href" : "http://localhost:8080/relationships/customer%20%5bid=2,%20firstname=f,%20lastname=l%5d/customer1"         },         "customer2" : {           "href" : "http://localhost:8080/relationships/customer%20%5bid=2,%20firstname=f,%20lastname=l%5d/customer2"         }       }     } ]   } } 

question: has succeeded in using spring data rest mapping entities? can spot mistake in implementation? or bug? (i'm using spring boot 1.2.4.release starter-data-rest , starter-data-jpa, should latest releases)

please, no suggestions change schema. know can fix inserting generated @id relationship, schema given as-is.

i solve problem custom backendidconverter.

spring data rest composite primary key

hope you.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -