All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.type.SerializableType Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.type;

import java.io.Serializable;

import org.hibernate.type.descriptor.java.SerializableTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor;

/**
 * A type that maps between a {@link java.sql.Types#VARBINARY VARBINARY} and {@link Serializable} classes.
 * 

* Notice specifically the 2 forms:

    *
  • {@link #INSTANCE} indicates a mapping using the {@link Serializable} interface itself.
  • *
  • {@link #SerializableType(Class)} indicates a mapping using the specific class
  • *
* The important distinction has to do with locating the appropriate {@link ClassLoader} to use during deserialization. * In the fist form we are always using the {@link ClassLoader} of the JVM (Hibernate will always fallback to trying * its classloader as well). The second form is better at targeting the needed {@link ClassLoader} actually needed. * * @author Gavin King * @author Steve Ebersole */ public class SerializableType extends AbstractSingleColumnStandardBasicType { public static final SerializableType INSTANCE = new SerializableType<>( Serializable.class ); private final Class serializableClass; public SerializableType(Class serializableClass) { super( VarbinaryTypeDescriptor.INSTANCE, new SerializableTypeDescriptor( serializableClass ) ); this.serializableClass = serializableClass; } public String getName() { return (serializableClass==Serializable.class) ? "serializable" : serializableClass.getName(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy