-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Null varchar comes out as empty String
PostPosted: Tue May 16, 2006 12:46 pm 
Newbie

Joined: Wed Nov 02, 2005 12:50 pm
Posts: 5
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.