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.  [ 5 posts ] 
Author Message
 Post subject: It's possible with hibernate,urgently
PostPosted: Fri Mar 18, 2005 4:36 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Hi,

i'm using hibernate for our db2/400/legacy, i have using userType for receiving data that trimmed and work fine.
But i have a problem when i'm going in update/insert, because our db not accept null field.
It's possibile to say to Hibernate that all field of String type not put null value but blank value?
Can yuo help me please.

Devis

Hibernate version3rc1:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 4:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why dont you just implement that in your UserType ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 4:56 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
thank's i'm testing my UserType now,because I thought that Hibernate used alone UserType to receive the data but that it didn't ignore it in update/insert.
I have made this change but don't work can you help me?
Devis


Code:
package dao.hibernate;



import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.*;
import org.hibernate.usertype.*;
import java.io.Serializable;
/**
* @author Colin Hawkett
*/
public class TrimmedString implements UserType,Serializable
{
    public TrimmedString() {
        super();
    }

    public int[] sqlTypes() {
        return new int[] { Types.VARCHAR };
    }

    public Class returnedClass() {
        return String.class;
    }

    public boolean equals(Object x, Object y) throws HibernateException {
        return (x == y) || (x != null && y != null && (x.equals(y)));
    }

    public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {

        String val = rs.getString(names[0]);


        return val != null ? val.trim() : "";
    }

    public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {

        st.setString(index, (String)value);
    }

    public Object deepCopy(Object value) throws HibernateException {
        if (value == null) return null;
        return new String((String)value);
    }

    public boolean isMutable() {
        return false;
    }


public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}

public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}

public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}

public Object replace(Object original, Object target, Object owner)
throws HibernateException {
return original;
}


}



Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 5:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what do you think nullSafeSet does ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 5:10 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
GREAT MAX,
thank's for you help, sorry but i'm a newbie with this great product.
Bye


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.