Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用org.springframework.orm.hibernate4.LocalSessionFactoryBean在Hibernate中注册自定义类型_Spring - Fatal编程技术网

如何使用org.springframework.orm.hibernate4.LocalSessionFactoryBean在Hibernate中注册自定义类型

如何使用org.springframework.orm.hibernate4.LocalSessionFactoryBean在Hibernate中注册自定义类型,spring,Spring,我正在从hibernate 3迁移到hibernate 4, 在hibernate 3中,我注册自定义类型的方式是: public class AnnotationSessionFactoryBean extends org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean { private Collection<? extends BasicType> customTypes; publ

我正在从hibernate 3迁移到hibernate 4, 在hibernate 3中,我注册自定义类型的方式是:

public class AnnotationSessionFactoryBean extends org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean {
private Collection<? extends BasicType> customTypes;

public Collection<? extends BasicType> getCustomTypes() {
    return customTypes;
}

public void setCustomTypes(Collection<? extends BasicType> customTypes) {
    this.customTypes = customTypes;
}

@Override
protected Configuration newConfiguration() throws HibernateException {
    Configuration configuration = super.newConfiguration();
    if (CollectionUtils.hasEntries(customTypes)) {
        for (BasicType customType:customTypes) {
            configuration.registerTypeOverride(customType);
        }
    }
    return configuration;
}}
公共类AnnotationSessionFactoryBean扩展org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean{

private Collection在一个实体类中,按如下方式注释该类:

@TypeDefs({
  @TypeDef(name="type1",typeClass=me.sample.Type1.class),
  @TypeDef(name="type2",typeClass=me.sample.Type2.class)
})

Spring 3.1将AnnotationSessionFactoryBean与LocalSessionFactoryBean合并,授权Hibernate配置是否使用注释与XML连接。

在Hibernate 4中,您可以使用
LocalSessionFactoryBean
,而无需扩展它:

sessionFactory.getConfiguration().registerTypeOverride(TypeOverride.INSTANCE);
不过,在Hibernate 5.0中,这将消失:


注意:在4.0版本发布后,将使用org.hibernate.boot.registry.StandardServiceRegistryBuilder和org.hibernate.metamodel.MetadataSources代替该类,此时该类将被弃用并计划在5.0中删除。有关详细信息,请参见HHH-6183、HHHH-2578和HHHH-6586

我必须在哪里添加该类?