Kategorien
Java

„Hibernate – A Developers Notebook“ – migrating to Hibernate 3.0, Chapter 7

Chapter 7 is working in Hibernate 3 (as opposed to chapter 6). The most challanging in this chapter migrationwise are StereoVolumeType.java and SourceMediaType.java . Change the import-package names. The Usertype-stuff is now under the package „org.hibernate.usertype“. It won’t compile, yet as there are some methods missing. For SourceMediaType.java:

  1. public Object replace(Object original, Object target, Object owner)
  2.     throws HibernateException {
  3.  
  4.         return original;
  5.    }
  6.  
  7. public Serializable disassemble(Object value) {
  8.        return (Serializable) deepCopy(value);
  9.  }
  10.  
  11. public Object assemble(Serializable cached,
  12.                            Object owner)
  13.     {
  14.         // Our value type happens to be serializable, so we have an easy out.
  15.         return deepCopy(cached);
  16.     }
  17.  
  18. public int hashCode(Object o) { return o.hashCode(); }

For StereoVolumeType.java:

  1. public Object replace(Object original, Object target,SessionImplementor session,
  2.                       Object owner)
  3.     throws HibernateException {
  4.                    
  5.                    return deepCopy((StereoVolumeType)original);
  6.   }
  7.                
  8. public int hashCode(Object o) { return o.hashCode(); }
  9.  
  10. public Object replace(Object original, Object target, Object owner)
  11.                throws HibernateException {
  12.                    
  13.                    return original;
  14.  }

That’s it.