Java 升级到Hibernate 5.0.2后出现性能问题-Tomcat服务器启动时间增加
将Hibernate版本从4.3.9.Final升级到5.0.2.Final后,Tomcat服务器的启动时间增加了 调试后,我意识到hibernate在元数据源中添加映射位置(*.hbm.xml文件)花费了太多时间 我使用以下代码在会话工厂中添加了映射位置,在我的项目中大约有1000个hbm.xml文件Java 升级到Hibernate 5.0.2后出现性能问题-Tomcat服务器启动时间增加,java,spring,hibernate,hibernate-5.x,Java,Spring,Hibernate,Hibernate 5.x,将Hibernate版本从4.3.9.Final升级到5.0.2.Final后,Tomcat服务器的启动时间增加了 调试后,我意识到hibernate在元数据源中添加映射位置(*.hbm.xml文件)花费了太多时间 我使用以下代码在会话工厂中添加了映射位置,在我的项目中大约有1000个hbm.xml文件 <bean id="baseSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBea
<bean id="baseSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.jdbc.fetch_size">300</prop>
<prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
<property name="mappingLocations">
<list>
<value>classpath*:com/*/**/*.hbm.xml</value>
</list>
</property>
</bean>
在配置类的元数据源对象中添加所有映射位置需要花费太多时间
if (this.mappingLocations != null) {
// Register given Hibernate mapping definitions, contained in resource files.
for (Resource resource : this.mappingLocations) {
sfb.addInputStream(resource.getInputStream());
}
}
这里有没有提高性能的解决方案?升级到Hibernate-5后有人注意到这样的问题吗?对于初学者,不要扫描
com
包,但更具体地说,这样扫描速度更快,但是添加它不应该改变那么多,我想说的是,主要的罪魁祸首是Hibernate在添加映射时做了更多/额外的事情。我已经给出了更具体的扫描路径,但是扫描不会花费太多时间。大部分时间都被for循环占用,我在问题中提到了for循环用于添加映射位置。然后,问题出现在hibernate中,因为添加是由hibernate完成的(addInputStream是对hibernate的调用)。所以我想你必须弄清楚这些版本之间发生了什么变化。。。我知道整个内部配置机制都被彻底检修了,所以可能与此有关。我们在这里谈论的是什么样的增长?秒?在任何情况下,作为一个回归bug来报告似乎都是值得的。拥有如此多的映射文件看起来像是一个压力测试,Hibernate团队可能没有自己做过。
if (this.mappingLocations != null) {
// Register given Hibernate mapping definitions, contained in resource files.
for (Resource resource : this.mappingLocations) {
sfb.addInputStream(resource.getInputStream());
}
}