Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.