-->
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: custom type does not implement Serializable
PostPosted: Thu Oct 07, 2004 10:24 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I've a UserType to handle NULL values for booleans as false. It works fine.
Up on start-up Hibernate complains that it doesn't implement the Serializable interface also it does.

Any ideas?
Ernst

Debug level Hibernate log excerpt:
Code:
...
WARNUNG    CustomType    <init>: custom type does not implement Serializable: class ch.bedag.gba.cap.server.persistence.hibernate.BooleanPersistentType
...


Implementation of the BooleanPersistentType
Code:
public class BooleanPersistentType implements Serializable, UserType {
   
   private static final ch.bedag.gba.common.logging.CapiLogger LOG = ch.bedag.gba.common.logging.CapiLoggerFactory
               .getLog(BooleanPersistentType.class);

   public BooleanPersistentType(){
      super();
   }
   
   public int[] sqlTypes() {
      return new int[]{Types.SMALLINT};
   }

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

   public boolean equals(Object x, Object y) throws HibernateException {
      if (x == y) return true;
      if (x == null || y == null) return false;
      return x.equals(y);
   }

   public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
      Integer i = (Integer) Hibernate.INTEGER.nullSafeGet(rs, names);
      if (i==null || i.intValue()==0) {
         return Boolean.FALSE;
      }
      else {
         return Boolean.TRUE;
      }
   }

   public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
      if (value==null) value = Boolean.FALSE;
      Boolean b = (Boolean)value;
      if (Boolean.TRUE.equals(b)) {
         st.setInt(index, 1);
      }
      else {
         st.setInt(index, 0);
      }
   }

   public Object deepCopy(Object value) throws HibernateException {
      return value;
   }

   public boolean isMutable() {
      return true;
   }

}


Hibernate version:
2.1.7 (Nightly Snapshot of 4.10.2004)

Mapping documents:
Code:
...
      <property name="myGueltig" column="FBF08" access="field" type="ch.bedag.gba.cap.server.persistence.hibernate.BooleanPersistentType"/>
...


Name and version of the database you are using:
Oracle 9.2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 10:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Place the Serializable reference last in the list of implemented interfaces.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 08, 2004 7:27 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Thanks for your answer david.

I changed the code to

Code:
...
public class BooleanPersistentType implements UserType, Serializable {
...


Unfortunately I still get the same warning :-).

Is there soemthing I'm missing about serialization?

TIA
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 5:34 am 
Newbie

Joined: Mon Sep 26, 2005 10:00 am
Posts: 3
The answer is late, but could be meaningful.

After having read the sources I think that the serializable test is made against the Class returned by the method returnedClass(), and not against the Class that implements UserType. In your case the native class boolean.

Here is the code (look at the last statement...) :
Code:
   public CustomType(Class userTypeClass) throws MappingException {
      
      name = userTypeClass.getName();

      try {
         userType = (UserType) userTypeClass.newInstance();
      }
      catch (InstantiationException ie) {
         throw new MappingException( "Cannot instantiate custom type: " + userTypeClass.getName() );
      }
      catch (IllegalAccessException iae) {
         throw new MappingException( "IllegalAccessException trying to instantiate custom type: " + userTypeClass.getName() );
      }
      catch (ClassCastException cce) {
         throw new MappingException( userTypeClass.getName() + " must implement net.sf.hibernate.UserType" );
      }
      types = userType.sqlTypes();

      if (!Serializable.class.isAssignableFrom( userType.returnedClass() ) ) {
         LogFactory.getLog(CustomType.class).warn("custom type does not implement Serializable: " + userTypeClass);
      }
      
   }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 2:46 pm 
Newbie

Joined: Tue Nov 22, 2005 3:16 pm
Posts: 4
boolean.class is not serializable... its a primitive. Have you tried using Boolean.class instead?


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.