如何使用org.springframework.orm.hibernate4.LocalSessionFactoryBean在Hibernate中注册自定义类型
我正在从hibernate 3迁移到hibernate 4, 在hibernate 3中,我注册自定义类型的方式是:如何使用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
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我必须在哪里添加该类?