Hi everyone,
Actually,I'm new to Hibernate.I need a suggestion regarding selectively update fields.
I'm using Spring + Hibernate.
I have a table Emp in Db. I have followed class per table structure and created class Emp. Now class Emp have 4 fields.e.g id,Name,address,age. id is generated by sequence.
If I use hibernateTemplate.saveOrUpdate() for savinf as well as updating.
i> If the record is not present in DB is it inserted.
ii> If the record is already in DB it is updated. Now here is my question.
I have a record of Employee in DB.
id - 34
name- Alex
Address - 23/3 xyz road
age -45
At some point of my application,I have to modify the age and address of this employee.But from service layer I'm getting updated age. All others fields are Null.
I have to update only the age -> I have following ways ---
1. I cant use saveOrUpdate() becuase in that case except age and id field all the other fields will be NULL.
2. I have to retrieve that emp object(dbEmp)
3. map the not null fields of serEmp(i.e Emp from Service layer) to dbEmp.
4.Update the dbEmp.
Is their ANY OTHER way to dynamically update NOT NULL fields of any table despite "calling a retrieve before update " ?
Pleasse Help Me.
|