If I have an instance of a persistence object, and I set some members in like so:
MyThing thing = session.get(MyThing.class, id);
thing.setSomething(thing.getSomething());
session.update(thing);
Will this actually cause hibernate to issue an SQL update command to refresh the record? Or is hibernate smart enough to know that the object was updated, but the values have not actually changed?
In general, it should not issue an update if the property values compare equal. (Specifically, compare equal according to their Type implementation— which is usually the same as their equals(Object) method).
nemo was right, you should always be aware of what SQL Hibernate is executing. Although I recommend setting the ‘org.hibernate.SQL’ logger (‘net.sf.hibernate.SQL’ for Hibernate 2) to DEBUG level (in log4j) rather than using the “show_sql” property (which always writes to System.out or System.err iirc).
(Although I think you meant
session.flush(), notsession.update(thing)… unless you’re using a stateless session?)