如何在Spring中添加自定义Hibernate类型

时间:2018-04-26 12:13:25

标签: java spring hibernate

问题:我将使用@ vlad-mihalcea的Hibernate-Types。但我需要使用自己的ObjectMapper实例(Spring bean)。怎么做?

详细信息:Vald解释here如何注册自定义ObjectMapper。但是我仍然不知道在哪里准确添加属性。

是否应将properties对象传递给LocalContainerEntityManagerFactoryBean,如下所示?

@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        EntityManagerFactoryBuilder builder,
        DataSource dataSource,
        JpaProperties jpaProperties,
        JpaSchemaGenerationProperties schemaGenerationProperties) {

    LocalContainerEntityManagerFactoryBean factory = builder
            .dataSource(dataSource)
            .packages("foo", "bar")
            .persistenceUnit("default")
            .properties(jpaProperties.getHibernateProperties(dataSource))
            .build();

    Map<String, Object> jpaPropertyMap = createDefaultJPAConfigMap(env, schemaGenerationProperties);
    // Should I add the property here?

    factory.setJpaPropertyMap(jpaPropertyMap);
    return factory;
}

0 个答案:

没有答案