我正在使用Spring(Boot)构建REST webservice,并尝试在没有任何xml配置的情况下使用hibernate作为ORM映射器。我基本上让它工作了,但我卡在了一个配置问题上。我在@Configuration文件中将LocalContainerEntityManagerFactoryBean实例化为@Bean。我像以下示例一样设置hibernate.ejb.naming_strategy -> 如果表不存在,则这似乎适用于创建表(列名与@Entity类中的camelCase相同),但是当执行查询时,hibernate会“忘记”此命名配置并尝试使用另一种下划线属性的命名策略->显然这些查询失败。是否还有其他需要设置的属性?或者更喜欢不添加cfg.xml或persistence.xml的方式来配置属性?
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
Properties props = new Properties();
props.put("hibernate.hbm2ddl.auto", "create");
props.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.DefaultNamingStrategy");
lef.setJpaProperties(props);
lef.afterPropertiesSet();