CLONE -nullSafeGet not null safe HIB-103
----------------------------------------

         Key: HIB-166
         URL: http://jira.andromda.org/browse/HIB-166
     Project: Hibernate Cartridge
        Type: Bug
    Versions: 3.0 Final    
 Environment: HIbernate/Spring cartridge
    Reporter: Darius Schier
 Assigned to: Wouter Zoons 


Hi there,
HibernateByteBlobType.nullSafeGet and nullSafeSet are not null save, NPE are 
thrown in both cases if the value is null.
I would suggest something like that:

    public void nullSafeSet(PreparedStatement st, Object value, int index)
        throws SQLException
    {
        byte[] b = (byte[])value;
        if(b!= null ) {
           st.setBinaryStream(index, new ByteArrayInputStream(b), b.length);
        } else {
           st.setBinaryStream(index,null,0);
        }
    }

    public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
        throws SQLException
    {
        Blob blob = rs.getBlob(names[0]);
        if(blob == null) {
            return null;
        } else {
            return blob.getBytes(1, (int)blob.length());
        }
    }


Regards
Darius




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642

Reply via email to