tags:

views:

70

answers:

2

I've got a Hibernate model that uses a custom type to represent boolean fields (ie, model has a 'Boolean' object, but the database writes a 0 or 1 to a TINYINT field. Changing the value of the boolean object from (true to false or false to true) will change the value on the object, but the Hibernate session manager doesn't seem to think the object had any values change, and therefore save() does not actually write SQL to the DB.

Do I need to do something special in my custom type to get it to see changes? I'd prefer that to forcing each object to 'dirty' itself in accessors, but that's also possible.

A: 

Firstly, is there any reason that you're using your custom type instead of Hibernate's built-in boolean type?

<property name="some_flag" type="boolean"/>

Secondly, no, you don't need to do anything "special" in your custom type but you do need to properly implement its equals() and deepCopy() methods among others. Can you post the source?

ChssPly76
A: 

save() doesn't actually save the object (or it's changes) to the database. It marks it as persistent, i.e. an object that Hibernate thinks is managed. If the object is detached, call update().

Are you flushing the Session when your work is done? And/or closing it?

You might want to double-check the Hibernate manual on Modifying Persistent Objects (I don't say this to be snippy; I had the same issue with Hibernate myself today - forgot the difference between save() and other methods, and also forgot to flush() my session).

matt b