tags:

views:

36

answers:

1

I have object in database with values as follows: id =1 name = "john" chargeid = 6

I am using merge statemet to update the code em.merge(obj)

When i see the query generated by JPA i found that in update query only fields which has new or not null values are updated.

I checked the bean which is associated with this object and found that there is no annotations associated ith chargid

Now when i try to update this JPA, it gets properly updated if i dont set anyvalue to null. Now if i set chargeid= null and then try to set persist it into db, it doeskin get changed to null in db but it retails the previous value.How come?

The folloing are the details 1 have record in database as follows

ID     Name   chargeID
1     john      5   

Now if i set values of objects as

obj.setID(1),
obj.setName("johnNew")
obj.setchargID(6)
entinymanager.merge(obj)

then record is updated as follows, which is fine

Id  name      chargeid
1    johnNew   6

Now if i want to set chargeid to null i use code

obj.setId(1)
obj.setName('XYZ')
obj.setChargeId(null); // i want to update it as null.

Now the record will be updated as follows

id  name  chargeid
1   XYZ    6        //name is updated to XYZ,but chargeid is not updated to null, how come?


i want to set chargeid to null.
A: 

Perhaps you have an 'not null' defined for the chargeid column? (In your database)

Jochem
This should raise an error, not result in a partial update.
Pascal Thivent
i checked the bean, it doesnnot have not null defined.And am notgeting any error.only chargeId field is not updated to null, it retains previous value
akp