我正在使用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();
}
}