How should I register custom Hibernate 5 data type (BasicType) when Spring Data is used?

后端 未结 4 1269
栀梦
栀梦 2021-02-13 17:40

I use Spring Data and decided that I want to create new custom data type that can be used in Hibernate entities. I checked the documentation and choose BasicType an

4条回答
  •  借酒劲吻你
    2021-02-13 18:10

    I use JPA with Spring 4.3.9 and Hibernate 5.0.5 and I use custom property EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS with Spring LocalContainerEntityManagerFactoryBean to override Hibernate BasicTypes.

    final Properties jpaProperties = new Properties();
    jpaProperties.put(EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS, new TypeContributorList() {
        @Override
        public List getTypeContributors() {
             return Lists.newArrayList(new CustomDateTimeTypeContributor());
        }
    });
    final LocalContainerEntityManagerFactoryBean factoryBean = new 
    LocalContainerEntityManagerFactoryBean();
    factoryBean.setJpaProperties(jpaProperties);
    factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
    return factoryBean;
    

提交回复
热议问题