Reputation: 3
i am using sybase db and hibernate as ORM tool, I am dealing with Person object, which contains name as String variable, i have used varchar datatype in db side when i create object of Person as
Person p=new Person();
p.setName(null);
session.saveOrUpdate(p);
this works fine
but when i put empty string in name it creates white space in db.
Person p=new Person();
p.setName("");
session.saveOrUpdate(p);
why this is happening ?
Any advice would be greatly appreciated..
Upvotes: 0
Views: 2169
Reputation: 1616
Its the database padding that adds the white space and nothing to do with hibernate.
Refering to
"Adaptive Server truncates entries to the specified column length without warning or error, unless you set string_rtruncation on. See the set command in the Reference Manual for more information. The empty string, ""or '', is stored as a single space rather than as NULL. Thus, "abc" + "" + "def" is equivalent to "abc def", not to "abcdef"."
Two things you could do:
Upvotes: 4
Reputation: 1751
Empty is a string value and hibernate think like it is a string with a value empty So it will create it. You can check "".equals(..) that means java treats "" as a value.
Upvotes: 1