Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring with Hibernate File Uploads and Entity Updates in Spring + Hibernate Updating Categories: Part 2

Using PUT instead of POST results in SpelEvaluationException!

While performing the update that Chris performs in the video, using RequestMethod.PUT instead of RequestMethod.POST on the updateCategory method results in the following exception:

org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'colorCode' cannot be found on null

Any idea why?

It seems, and correct me if I'm wrong, that PUT demands that both category name and colorCode be updated, whereas with POST any one of the fields can be updated.

1 Answer

You're right. "PUT replaces an existing entity. If only a subset of data elements are provided, the rest will be replaced with empty or null." https://spring.io/understanding/REST

Usually POST is used for create, so PUT is correct. Just need to send in all fields. Or you can use PATCH which allows you to do partial update.