Mezoo
Mezoo

Reputation: 769

Spring Rest Hibernate Update List with PUT method

I'm tying to update List with a rest service, but an InvalidDataAccessApiUsageException is thrown :

Parameter value element [Sharing{uuid=af777b47-3dfc...updated=2016-05-04T10:37:29.000Z}]  did not match expected type [java.util.UUID (n/a)]

Controller :

@RequestMapping(value = "/updateChecked", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public int update(@RequestBody SharingList shares){
    return this.sharingService.updateChecked(shares);
}

Service :

public int updateChecked(SharingList shares) {
        int updated = sharingDao.setCheckedSharingFor(shares);
        return updated;
    }

DAO :

@Modifying
@Query("UPDATE Sharing s SET s.checked=1 WHERE uuid in :shares")
int setCheckedSharingFor(@Param("shares") SharingList shares);

SharingList:

public class SharingList extends ArrayList<Sharing> {

}

What is wrong please ?

Upvotes: 0

Views: 753

Answers (1)

v.ladynev
v.ladynev

Reputation: 19956

There is the answer here

Sharing{uuid=af777b47-3dfc...updated=2016-05-04T10:37:29.000Z}]  
did not match expected type [java.util.UUID (n/a)]

Hibernate doesn't have artificial intelligence to understand that it should get uuid from Sharing.

Fo this query

@Query("UPDATE Sharing s SET s.checked=1 WHERE uuid in :shares")

you should provide a collection of UUID as the shares parameter.

Upvotes: 1

Related Questions