HIBERNATE JBoss.org
 |  Register  | 
     
News 
About 
   Feature List 
   Road Map 
Documentation 
   Related Projects 
   External Documentation 
Download 
Forum & Mailinglists 
Support & Training 
JIRA Issue Tracking
Wiki Community Area


Hibernate Public Training Courses


Get Hibernate in Action eBook!


JavaWorld 2003 Finalist


Jolt Award 2004 Winner
      
Documentation > Community Area > UserType for persisting Typesafe Enumerations with a single class > Comments > Check on null value


Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
Subject: Check on null value 22 Jul 2004, 09:45
From: zombieman Replies: 0, Views: 107
 
I've made some changes to the nullSafeSet function.  It's possible that
your association is not required, then you have to store a null value in
the database.


/**
     * @see
net.sf.hibernate.UserType#nullSafeSet(java.sql.PreparedStatement,
java.lang.Object, int)
     */
    public void nullSafeSet(PreparedStatement st, Object value, int
index) throws HibernateException, SQLException {
        // make sure the received value is of the right type
        if ((value != null) &&
!returnedClass().isAssignableFrom(value.getClass())) {
            throw new IllegalArgumentException("Received value is not a [" +
                    returnedClass().getName() + "] but [" +
value.getClass() + "]");
        }

        if (value == null) {
            st.setNull(index, getNullableType().sqlType());
        } else {
            // convert the enum into its persistence format
            Serializable enumCode = ((PersistentEnum) value).getEnumCode();

            // set the value into the resultset
            st.setObject(index, enumCode, getNullableType().sqlType());
        }
    }
 

Thread:
 Check on null value 
 zombieman   22 Jul 2004, 09:45 
      

coWiki