使用Spring,Hibernate和Jersey与现有应用程序并行开发Web服务。最初我使用的实体类少于20个,服务器启动时间不到45秒。现在我添加了所有191个实体类,我稍后需要这些类。添加后,我的应用程序需要大约7分钟才能启动。顺便说一句,我使用Tomcat 7作为我的服务器。
在日志中我可以看到很多
o.h.ejb.packaging.AbstractJarVisitor - Filtering:............
o.h.cfg.annotations.CollectionBinder - Collection role:.......
o.h.cfg.annotations.PropertyBinder - Building property.......
org.hibernate.cfg.Ejb3Column - Binding column: Ejb3JoinColumn{....
org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table.....
o.h.c.annotations.SimpleValueBinder - Setting SimpleValue typeName for .....
o.hibernate.cfg.CollectionSecondPass - Second pass for collection:......
o.h.cfg.annotations.CollectionBinder - Binding a OneToMany: .....
o.h.cfg.annotations.CollectionBinder - Mapping collection: .....
o.h.cfg.annotations.TableBinder - Retrieving property ......
org.hibernate.cfg.Configuration - Resolving reference to class: .....
o.h.c.e.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [.....]; using defaults.
net.sf.ehcache.Cache - Initialised cache: .....
n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for '.....
o.h.c.e.AbstractEhcacheRegionFactory - started EHCache region:....
o.h.p.entity.AbstractEntityPersister - Static SQL for entity:.....
o.h.p.entity.AbstractEntityPersister - Version select: .....
o.h.p.entity.AbstractEntityPersister - Snapshot select:....
o.h.p.entity.AbstractEntityPersister - Insert 0: .....
o.h.p.entity.AbstractEntityPersister - Update 0: ....
o.h.p.entity.AbstractEntityPersister - Delete 0: ....
o.h.p.c.AbstractCollectionPersister - Static SQL for collection:.....
o.h.p.c.AbstractCollectionPersister - Row insert: .....
o.h.p.c.AbstractCollectionPersister - Row update: .....
o.h.p.c.AbstractCollectionPersister - Row delete: .....
o.h.p.c.AbstractCollectionPersister - One-shot delete: ....
我观察到以下情况需要花费很多时间
org.hibernate.loader.Loader - Static select for entity ... [NONE]: ...
org.hibernate.loader.Loader - Static select for entity ... [READ]: ...
org.hibernate.loader.Loader - Static select for entity ... [UPGRADE]: ...
org.hibernate.loader.Loader - Static select for entity ... [UPGRADE_NOWAIT]: ...
org.hibernate.loader.Loader - Static select for entity ... [FORCE]: ...
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_READ]: ...
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_WRITE]: ...
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_FORCE_INCREMENT]: ...
org.hibernate.loader.Loader - Static select for entity ... [OPTIMISTIC]: ...
org.hibernate.loader.Loader - Static select for entity ... [OPTIMISTIC_FORCE_INCREMENT]: ...
org.hibernate.loader.Loader - Static select for action ACTION_MERGE on entity ... : ...
org.hibernate.loader.Loader - Static select for action ACTION_REFRESH on entity ...: ...
o.h.l.collection.OneToManyLoader - Static select for one-to-many
如何改善启动时间?
注意:使用Spring版本:4.1.4.RELEASE, Hibernate版本:4.2.7.Final
我正在使用java配置,你可以在spring + hibernate + c3p0 + ehcache java configuration看到我的java配置。不使用单独的persistence.xml
答案 0 :(得分:0)
尝试在persistence.xml
:
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
它通常会加速Hibernate。
2016-04-14附加&#34; s&#34;纠正属性名称。