-->
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.  [ 3 posts ] 
Author Message
 Post subject: update bug
PostPosted: Sun Jan 25, 2004 8:38 am 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 9:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try setting not-null="true" for your property.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2004 12:08 pm 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
gloeglm wrote:
Try setting not-null="true" for your property.


well that works. thanks

nevertheless i find it quite disturbing that someone
is changing null values to empty strings underneath.

ciao robertj


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

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.