-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Ejb3Configuration.buildEntityManagerFactory performance
PostPosted: Sun Mar 17, 2013 7:25 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hi,

we have about 150 classes mapped to 150 tables, and build the
EntityManagerFactory as follows:

Code:
Ejb3Configuration cfg = new Ejb3Configuration();

Class[] types = new Class[150] { ....};
     
for (int i=0; i<types.length; i++)
  cfg.addAnnotatedClass(types[i]);
        
EntityManagerFactory emf = cfg.buildEntityManagerFactory();


It takes a long time, about 20 seconds. Is there a way to speed up? or initialize lazily?
Thanks.
Dave


Top
 Profile  
 
 Post subject: Re: Ejb3Configuration.buildEntityManagerFactory performance
PostPosted: Fri Mar 22, 2013 7:10 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Is there a way to speed up? or initialize lazily?


Lazy initialization is not provided by Hibernate.
I past I got a problem (only on Windows OS) where buildEntityManagerFactory stuck most time in scanning for
annotated classes in my jar-file. Since then I deploy the entity classes into a separate jar-file and refer it in my persistence.xml as follows:

Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"  version="2.0">

<persistence-unit>
   <jar-file>persistentclasses.jar</jar-file>
...


This did speed up buildEntityManagerFactory.
N.B.: in my case I let Hiberante scan automatically for annotated entity classes.


Top
 Profile  
 
 Post subject: Re: Ejb3Configuration.buildEntityManagerFactory performance
PostPosted: Sun Apr 07, 2013 8:33 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I added the entity class annotation explicitly, so it should spend no time on scanning. The time is spent on mapping to db table. How many classes do you have, how much time is taken for building entity manager factory? Thanks.


Top
 Profile  
 
 Post subject: Re: Ejb3Configuration.buildEntityManagerFactory performance
PostPosted: Tue Apr 09, 2013 4:35 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I have 226 entity classes resulting into 216 tables on database.
The whole startup takes 5444 ms on my computer, but the part of building the mapping takes less than 2,3 secs,
which is accectable for me, see following output.
I use a Intel Quadcore with 3.4 Gigahertz on Windows using JRE1.7 64bit.

10:26:56,177 INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
10:26:56,194 INFO Version:41 - HHH000412: Hibernate Core {4.2.0}
10:26:56,199 INFO Environment:224 - HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.cache.region.factory_class=org.hibernate.testing.cache.CachingRegionFactory, hibernate.connection.username=sa, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
10:26:56,199 INFO Environment:342 - HHH000021: Bytecode provider name : javassist
10:26:57,395 INFO CommonNamingStrategy:172 - Collision with reserved keyword: file
10:26:57,905 INFO ConnectionProviderInitiator:188 - HHH000130: Instantiating explicit connection provider: org.hibernate.connection.TomcatJDBCConnectionProvider
10:26:58,480 INFO Dialect:127 - HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008CustomDialect
10:26:58,528 INFO TransactionFactoryInitiator:73 - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
10:26:58,537 INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
10:26:58,763 INFO UpdateTimestampsCache:61 - HHH000250: Starting update timestamps cache at region: hibernate.test.org.hibernate.cache.spi.UpdateTimestampsCache
10:26:58,773 INFO StandardQueryCache:86 - HHH000248: Starting query cache at region: hibernate.test.org.hibernate.cache.internal.StandardQueryCache
10:27:00,319 WARN AbstractEhcacheRegionFactory:180 - HHH020003: Could not find a specific ehcache configuration for cache named [hibernate.test.CollectionSettings]; using defaults.
(*) The database server services are ready..! [TestServer1][instance:mq4o2c]
Time start (ms):5444


Top
 Profile  
 
 Post subject: Re: Ejb3Configuration.buildEntityManagerFactory performance
PostPosted: Tue Apr 09, 2013 4:56 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi, a simple way to detect where the bottleneck is,
is to perform a serie of kill -3 <javapid> or jstack <javapid> on your javaprocess while its building the EntityManagerFactory.
This gives out the current stacktrace of your application,
so if the whole process takes about 20 secs, I guess that stacktraces will show where the thread is stucking the most time.
Maybe you could report here some stacktrace ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.