I'm using Spring and Hibernate in a web application. I have an entity as follow:
@Entity
public class MyClass{
@Id
@GeneratedValue
protected Long id;
protected String prop1;
protected String prop2;
/*
* Getters And Setters
*/
}
When I want to update an instance of this entity, I get the instance from client by using jackson as follow:
@Inject
SessionFactory sf;
@RequestMapping("update")
@Transactional
public void update(@RequestBody MyClass myClass){
sf.getCurrentSession.update(myClass);
}
User data is as follow:
{
"prop1": "my value1",
"prop2": "my value2"
}
this work correctly. My problem is when I want to update only prop1
. In this state, I have to set prop2
too. If I don't, it update prop2
to null
.
How can only update prop
without sending prop2
from client to server?