5

hibernate3からhibernate4に移行しています。hibernate3では、カスタムタイプを登録する方法は次のとおりです。

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;
}}

私は今同じ操作を行おうとしていますが、Hibernate 4を使用していますが、私の質問はこれを行うための最良の方法は何ですか?「org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean」の代わりに「org.springframework.orm.hibernate4.LocalSessionFactoryBean」を使用すると、アクセス権がないため、構成を変更できます。

ありがとう

4

2 に答える 2

3

エンティティクラスの1つで、次のようにクラスに注釈を付けます。

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

Spring 3.1はAnnotationSessionFactoryBeanをLocalSessionFactoryBeanとマージし、アノテーションとXMLワイヤリングを使用するかどうかをHibernate構成に委任しました。

于 2012-12-17T17:01:06.377 に答える
3

Hibernate 4では、LocalSessionFactoryBean拡張せずに使用できます。

sessionFactory.getConfiguration().registerTypeOverride(TypeOverride.INSTANCE);

ただし、これはHibernate5.0でなくなります。

注:これは、4.0リリース以降、代わりにorg.hibernate.boot.registry.StandardServiceRegistryBuilderおよびorg.hibernate.metamodel.MetadataSourcesを使用するように置き換えられます。この時点で、このクラスは非推奨になり、5.0で削除される予定です。詳細については、HHH-6183、HHH-2578、およびHHH-6586を参照してください。

于 2014-02-26T13:47:30.827 に答える