Selective/dynamic update with hibernate
we have a User entity with a password field, and two use cases:
1) update the user entity but not the password field, the entity is sent from the UI and has null in the password field.
2) update the user entity including the password,again the entity is sent from the UI.
in both use cases it is assumed that the entity is not attached to the hibernate session.
so using just saveOrUpdate in the first use case will set null to the password field in the DB(I'm ignoring the DB constraints for now),
and my understanding is that hibernate merge is not the solution.
my question is how to implement it without having to do two round trips to the DB and without having to write HQL statements.
my thoughts where to use the Seppuku pattern:
have two entity classes mapped to the same table
UserWP extends User
where in User the password fields will be update=false and use this entity in the first use case.
in UserWP the password field is update=true and use that for the second use case,actually the rest of the application only knows about User and the the UserDao method updateWithPassword converts User to UserWP and saves it.
is there a more elegant,maybe dynamic, solution?