I have a column as a varchar named "objective" that accepts <NULL> mapped to a String like so:
<property name="objective">
<column name="objective"/>
</property>
Upon insertion of a new object the column will receive and store <NULL>.
When the object is retrieved, an empty string ("") is pulled back. If another column is then altered, that empty string is stored in the db.
If the object is retrieved yet again, a single length string is retrieved (" ").
This is highly disturbing. Null and empty string are not the same thing.
I've tried altering the setter like so:
public void setObjective(String objective) {
if("".equals(objective))
this.objective= null;
else
this.objective= url;
}
and have considered also doing something similar to:
http://hibernate.org/242.html
However, in the first case, and as is pointed out in the comments of the second, this marks the object as dirty so an update will be executed whether or not we actually changed anything meaningful. This is not efficient.
Can somebody point me in the right direction? Whether that is doing something with Hibernate or looking at my db?
I'm using Hibernate 3.1 and MS Sql Server 2000 having tired both the MS supplied JDBC drivers and i-net SprintA.