使用JPA,H2,EclipseLink,Java Config(无xml)进行驼峰案例表/列名称转换

时间:2014-10-27 05:30:13

标签: spring-data-jpa eclipselink

我正在使用Spring-JPA,H2和EclipseLink Java配置(即没有xml),并希望实现表/列名称的驼峰式转换。例如,我希望@Entity MyTable转换为MY_TABLE

我见过一个例子:CamelCaseSessionCustomizer.java,但我不知道如何将它添加到我的@Configuration class中,摘录如下:

@ComponentScan(
        basePackages = { "com.foo.*" },
        excludeFilters = @Filter(type = FilterType.ANNOTATION,
        value = Configuration.class))
@Configuration
@EnableJpaRepositories(basePackages = "com.foo")
public class SeleniumAppTestConfig implements InitializingBean {

   @Bean
   public DataSource dataSource() {
     EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
     return builder.setType(EmbeddedDatabaseType.H2)
           .addScript("SeleniumCreateScript.sql")
           .build();
   }

   @Bean
   public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
      EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter();
      vendorAdapter.setGenerateDdl(true);
      vendorAdapter.setShowSql(true);

       LocalContainerEntityManagerFactoryBean emf =
           new LocalContainerEntityManagerFactoryBean();
       emf.setLoadTimeWeaver(new SimpleLoadTimeWeaver());
       final PersistenceProvider persistenceProvider = new PersistenceProvider();
       emf.setPersistenceProvider(persistenceProvider);
       emf.setPersistenceUnitName("SeleniumTests");
       emf.setJpaVendorAdapter(vendorAdapter);
       emf.setDataSource(dataSource());
       emf.setPackagesToScan("com.foo");
       return emf;
   }

   @Bean
   public EclipseLinkJpaDialect exceptionTranslator() {
       return new EclipseLinkJpaDialect();
   }

}

0 个答案:

没有答案