-->
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: Bug with nullSafeGet ?
PostPosted: Wed Jan 21, 2004 5:23 am 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
Hi.

I need to make a custom type that
- will set -1 on the object field if the db field is null
- will store null in db if the object field value = -1

I made one. It works for save but an error is returned on get.
I found that it was because of

Code:
    public final Object nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException {
                                                                                                                                           
        Object value = get(rs, name);
        if ( value==null || rs.wasNull() ) {
            if (IS_TRACE_ENABLED) LogFactory.getLog( getClass() ).trace("returning null as column: " + name);
            return null;
        }
        else {
      ....


This method, what ever is returned by get() will return null if the column was null.
So I can't return -1.
And as nullSafeGet is final, I can't override it.

I don't understand why it isn't rely on the get() method and return it's value what ever it is ?

Also, it is not my problem actually, but I saw that I wouldn't be able to store '-1' for a null field because there is another method


Code:
public final void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
                                                                                                                                           
        if (value==null) {
            if (IS_TRACE_ENABLED) LogFactory.getLog( getClass() ).trace("binding null to parameter: " + index);
                                                                                                                                           
            st.setNull( index, sqlType() );
        }
        else {
            if (IS_TRACE_ENABLED) LogFactory.getLog( getClass() ).trace("binding '" + toString(value) + "' to parameter: " + index);
                                                                                                                                           
            set(st, value, index);
        }
    }


that did not call set() of my type if the value is null.

Somebody can see a workaround ?

Thanks.

Mike[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 5:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What class are you extending there? Just implement UserType for your custom type.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 5:44 am 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
Ok. I made a shortcut !
As my column was a Long, I supposed easier to extend LongType.

I then will override alle methods of UserType.

Thanks !


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.