hi,
i have some strange behaviour when updating some
of my instances which prevent null field values.
i am working with hibernate version 2.1 and mysql 4.1
first here the table def
Code:
create table CONNECTOR
(ID CHAR(32) NOT NULL PRIMARY KEY,
NAME VARCHAR(50) NOT NULL ,
CONTACT VARCHAR(50) NULL ,
EMAIL VARCHAR(50) NULL ,
STATE VARCHAR(20) NOT NULL,
) TYPE = INNODB;
then the class being used
Code:
public class Connector
{
private String id_;
private String name_;
private String contact_;
private String email_;
private String state_;
public String getId(){return id_;}
public Connector setId(String _id){
id_ = _id;
return this;}
public String getName(){return name_;}
public Connector setName(String _name){
name_ = _name;
return this;}
public String getContact(){return contact_;}
public Connector setContact(String _contact){
contact_ = _contact;
return this;}
public String getEmail(){return email_;}
public Connector setEmail(String _email){
email_ = _email;
return this;}
public String getState(){return state_;}
public Connector setState(String _state){
state_ = _state;
return this;}
}
and finally the mapping
Code:
<hibernate-mapping>
<class
name="org.pragmatico.payment.entity.Connector"
table="CONNECTOR"
dynamic-update="false"
dynamic-insert="false"
>
<id name="id" column="id" type="java.lang.String">
<generator class="uuid.hex">
</generator>
</id>
<property name="name" type="java.lang.String"
update="true" insert="true" column="name"/>
<property name="contact" type="java.lang.String"
update="true" insert="true" column="contact"/>
<property name="email" type="java.lang.String"
update="true" insert="true" column="email"/>
<property name="state" type="java.lang.String"
update="true" insert="true" column="state"/>
</class>
</hibernate-mapping>
now somethin strange happens when i try to insert
null values for the name column. when creating a new
row i get an exception (which is to be expected) but
if i try to update an entity with a null value everything
works fine and the null value is converted into an
empty string.
any hints? is this a known bug in hibernate or in mysql?
here the example code.
Code:
Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Connector value = createConnector();
value.setName(null); //this will later initiate an exception
session.save(value);
tx.commit();
session.close();
return _value;
//the following code wont throw an exception even thou
//name is set to null also. instead the null value will
//be converted to an empty string ("")
Connector value = getExistingConnector();
Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
value.setName(null);
session.update(value);
tx.commit();
session.close();
any help is greatly appriciated.
ciao robertj