How do I modify only part of an entity in Spring Data JPA?
Here is my code.
public void modifyDrawing(Long no, String name, Double lat, Double lon, String physicalName, String desc) {
Drawing drawing = drawingRepository.findById(no)
.orElseThrow(NoSuchElementException::new);
drawing.setName(name);
drawing.setLat(lat);
drawing.setLon(lon);
drawing.setPhysicalName(physicalName);
drawing.setDesc(desc);
drawingRepository.save(drawing);
}
At this time, if lat
and lon
are null, I want to keep the values without changing them. I am wondering how to update the entity value using only non-null parameter values.