Hibernate 命名策略被忽略
Hibernate Naming Strategy is ignored
我通过 persistence.xml 在我的应用程序中配置了休眠,如下所示:
<persistence-unit name="entityManager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
并通过创建 EnityManagerFactory 的 EntityManagerUtil class:
Config config=CommonSettings.getInstance().config;
Map<String, Object> configOverrides = new HashMap<String, Object>();
configOverrides.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.ImprovedNamingStrategy");
configOverrides.put("hibernate.dialect",config.hibernateConfig.dialect);
configOverrides.put("hibernate.show_sql", config.hibernateConfig.showSql);
configOverrides.put("hibernate.max_fetch_depth", config.hibernateConfig.maxFetchDepth);
configOverrides.put("hibernate.jdbc.batch_size",config.hibernateConfig.batchSize);
configOverrides.put("hibernate.connection.pool_size", config.hibernateConfig.poolSize);
configOverrides.put("hibernate.connection.charSet", config.hibernateConfig.charSet);
configOverrides.put("hibernate.connection.characterEncoding",config.hibernateConfig.characterEncoding);
configOverrides.put("hibernate.connection.useUnicode", config.hibernateConfig.useUnicode);
configOverrides.put("hibernate.connection.autocommit", config.hibernateConfig.autocommit);
configOverrides.put("hibernate.connection.release_mode",config.hibernateConfig.releaseMode);
configOverrides.put("hibernate.cache.use_second_level_cache", config.hibernateConfig.useSecondLevelCache);
configOverrides.put("hibernate.cache.use_query_cache", config.hibernateConfig.useQueryCache);
configOverrides.put("hibernate.cache.use_structured_entries", config.hibernateConfig.useStructuredEntries);
configOverrides.put("hibernate.cache.region.factory_class",config.hibernateConfig.factoryClass);
configOverrides.put("packagesToScan", "org.prosolo.common.domainmodel");
configOverrides.put("javax.persistence.jdbc.driver",config.mysqlConfig.jdbcDriver);
configOverrides.put("javax.persistence.jdbc.url", "jdbc:mysql://"
+ host + ":" + port + "/" + database);
configOverrides.put("javax.persistence.jdbc.user", user);
configOverrides.put("javax.persistence.jdbc.password", password);
try{
emf = Persistence.createEntityManagerFactory("entityManager",
configOverrides);
}catch(Exception ex){
ex.printStackTrace();
}
我尝试在 persistence.xml 和配置覆盖中将命名策略配置为 ImprovedNamingStrategy。但是,它不起作用并且休眠会生成新的 tables 与 CamelCase table 名称。
知道我做错了什么吗?
谢谢
你的映射看起来很好,所以我怀疑配置被 bootstrap 进程中的某些东西覆盖了。
尝试在此代码块的 EntityManagerFactoryBuilderImpl.processProperties()
方法中添加一个断点:
else if ( AvailableSettings.NAMING_STRATEGY.equals( keyString ) ) {
namingStrategy = strategySelector.resolveStrategy( NamingStrategy.class, entry.getValue() );
}
else if ( AvailableSettings.NAMING_STRATEGY_DELEGATOR.equals( keyString ) ) {
namingStrategyDelegator = strategySelector.resolveStrategy( NamingStrategyDelegator.class, entry.getValue() );
}
看看配置是否可用。
我通过 persistence.xml 在我的应用程序中配置了休眠,如下所示:
<persistence-unit name="entityManager" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
并通过创建 EnityManagerFactory 的 EntityManagerUtil class:
Config config=CommonSettings.getInstance().config;
Map<String, Object> configOverrides = new HashMap<String, Object>();
configOverrides.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.ImprovedNamingStrategy");
configOverrides.put("hibernate.dialect",config.hibernateConfig.dialect);
configOverrides.put("hibernate.show_sql", config.hibernateConfig.showSql);
configOverrides.put("hibernate.max_fetch_depth", config.hibernateConfig.maxFetchDepth);
configOverrides.put("hibernate.jdbc.batch_size",config.hibernateConfig.batchSize);
configOverrides.put("hibernate.connection.pool_size", config.hibernateConfig.poolSize);
configOverrides.put("hibernate.connection.charSet", config.hibernateConfig.charSet);
configOverrides.put("hibernate.connection.characterEncoding",config.hibernateConfig.characterEncoding);
configOverrides.put("hibernate.connection.useUnicode", config.hibernateConfig.useUnicode);
configOverrides.put("hibernate.connection.autocommit", config.hibernateConfig.autocommit);
configOverrides.put("hibernate.connection.release_mode",config.hibernateConfig.releaseMode);
configOverrides.put("hibernate.cache.use_second_level_cache", config.hibernateConfig.useSecondLevelCache);
configOverrides.put("hibernate.cache.use_query_cache", config.hibernateConfig.useQueryCache);
configOverrides.put("hibernate.cache.use_structured_entries", config.hibernateConfig.useStructuredEntries);
configOverrides.put("hibernate.cache.region.factory_class",config.hibernateConfig.factoryClass);
configOverrides.put("packagesToScan", "org.prosolo.common.domainmodel");
configOverrides.put("javax.persistence.jdbc.driver",config.mysqlConfig.jdbcDriver);
configOverrides.put("javax.persistence.jdbc.url", "jdbc:mysql://"
+ host + ":" + port + "/" + database);
configOverrides.put("javax.persistence.jdbc.user", user);
configOverrides.put("javax.persistence.jdbc.password", password);
try{
emf = Persistence.createEntityManagerFactory("entityManager",
configOverrides);
}catch(Exception ex){
ex.printStackTrace();
}
我尝试在 persistence.xml 和配置覆盖中将命名策略配置为 ImprovedNamingStrategy。但是,它不起作用并且休眠会生成新的 tables 与 CamelCase table 名称。
知道我做错了什么吗?
谢谢
你的映射看起来很好,所以我怀疑配置被 bootstrap 进程中的某些东西覆盖了。
尝试在此代码块的 EntityManagerFactoryBuilderImpl.processProperties()
方法中添加一个断点:
else if ( AvailableSettings.NAMING_STRATEGY.equals( keyString ) ) {
namingStrategy = strategySelector.resolveStrategy( NamingStrategy.class, entry.getValue() );
}
else if ( AvailableSettings.NAMING_STRATEGY_DELEGATOR.equals( keyString ) ) {
namingStrategyDelegator = strategySelector.resolveStrategy( NamingStrategyDelegator.class, entry.getValue() );
}
看看配置是否可用。