Is there a way to disable it? I would like to minimize Hibernate sql if possible. The object that I get from the database should be 'clean' instead of 'dirty' so hibernate shouldn't need to update it. Right?

First the code is tough to read. There is a CODE button below Add Reply button to put CODE tags in your post so that you can put your actual code in between them and keep its indentation.

But I am thinking that there must be more to your code that you didn't post.

If you had loaded an object, made a change, then run a query, Hibernate will execute the update for the changed object when the query is run because in order for Hibernate to be sure that th query will return the correct results it needs to update/insert/delete data that might be changed that needs to be changed in the database so that the query gets the correct data.

Mark

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85

posted Nov 05, 2006 11:47:00

0

Thanks. Here is the code and mapping file. I appreciate if you can tell me why hibernate issues an UPDATE command. And how can I avoid it?

Code:

Mapping file:

sql generate by hibernate

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85

posted Nov 05, 2006 16:03:00

0

Here is the code I execute the query:

From the code, I did not modify the object I get from the query. So I don't understand why hibernate issues an update command.

Which line appears to be triggering the update sql to execute. (Is it happening during the commit?)

What was the value of version in the database before the select? Was it null?

Set the Hibernate log level to DEBUG. You should see some log entries that specify which property of cat is dirty. (Search for "dirty".)

ying lam
Ranch Hand

Joined: May 17, 2004
Posts: 85

posted Nov 05, 2006 17:28:00

0

Thank you for your help.

>> Why are you committing the transaction after the call to list()? This is because I just get the presistent object thru the query. And I return from the getCat() method , as a result, I commit the transaction before I return the 'Cat'.

>> Which line appears to be triggering the update sql to execute. (Is it happening during the commit?)

Yes, it happens during commit.

>> What was the value of version in the database before the select? Was it null? It was 0

>> Set the Hibernate log level to DEBUG. You should see some log entries that specify which property of cat is dirty. (Search for "dirty".)

Okay, i will try that.

Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518

posted Nov 05, 2006 19:33:00

0

[ying]It was 0

I'll bet that's the issue. Manually run an sql to set the version to 1 and see if the update still happens.

I think Hibernate sees the 0 and thinks it's a default value and that the object has never been persisted. [ November 05, 2006: Message edited by: Scott Johnson ]