views:

29

answers:

2

I want to use hibernate against an existing database. I need to mostly read data from the db and very occasionally modify a field.

I want to be able to update a single field in the row, but i need to make sure that all the other fields are not touched.

Does hibernate guarantee that a field will be written back the same as it was written (assuming i haven't modified the object)

+1  A: 

I want to be able to update a single field in the row, but i need to make sure that all the other fields are not touched.

That's possible if you use "dynamic updates". Here is what the documentation writes about this setting:

dynamic-update (optional - defaults to false): specifies that UPDATE SQL should be generated at runtime and can contain only those columns whose values have changed.

If you don't use this, all writable (see insert, update) properties will be part of the update.

But if you didn't change anything values, Hibernate won't change them on your back.

Pascal Thivent
+1  A: 

Make the other fields insertable=false, updateable=false should work. It should tell Hibernate that update on those field won't be reflected in DB

Adrian Shum
i ended up using this. Thanks.
Anthony