MemoryLeak
MemoryLeak

Reputation: 7318

What caused hibernate generate a update clause?

I am using Hibernate to select data from a View (defined as follows) :

from test where trim(id)='1111'

but hibernate generates the following update clause:

update test set id=?, dd=? where id='1111'

Anyone has any suggestion ? It seems it's a bug of Hibernate?

Upvotes: 2

Views: 2352

Answers (1)

jayunit100
jayunit100

Reputation: 17648

Hibernate can sometimes generate updates under-the-hood for you !

This happens, for example, if an object's state is out of sync with the database. You can override this behaviour (see the 2nd bullet below) as necessary... But often times it can effect some mistakes in your application's logic.

In your case : There are 2 reasons this can be happening :

1) Hibernate introspects the public methods (i.e. getters and setters) to set the fields in your mapping file, based on the HQL you send it as input. So... how does this effect your issue ? Well... if there is some sophisticated logic in your getters for your java beans, that logic could be causing hibernate to generate some updates, when you ultimately do this call, since those methods are being invoked.

2) There are some known corner cases where Hibernate does updates when you call select statements (i.e. dirty transactions). These can be fixed sometimes by setting "update=false" in your .hbm.xml files, in the appropriate places ...

See also : Using Enum in Hibernate causes select followed by an update statement

Upvotes: 4

Related Questions