Java 1.5 JPA with Hibernate and H2 is slow to create the EntityManagerFactory -
i'm trying test of our db layer in junit.
the problem have persistence.createentitymanagerfactory() takes > 200 seconds! googling h2, jpa, hibernate in combination createentitymanagerfactory gives nothing useful.
this test:
import static org.junit.assert.asserttrue; import java.util.date; import javax.persistence.entitymanager; import javax.persistence.entitymanagerfactory; import javax.persistence.persistence; import org.junit.test; public class minimalset { @test public void testnamedquery() { date starttime = new date(); entitymanagerfactory entitymanagerfactory = persistence.createentitymanagerfactory("testpersistence"); entitymanager entitymanager = entitymanagerfactory.createentitymanager(); date endtime = new date(); // did take less 10 seconds? asserttrue(((endtime.gettime() - starttime.gettime()) / 1000.0) < 10.0); } } this persistence.xml:
<?xml version="1.0" encoding="utf-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="testpersistence" transaction-type="resource_local"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.dialect" value="org.hibernate.dialect.h2dialect" /> <property name="hibernate.connection.url" value="jdbc:h2:mem:test" /> <property name="hibernate.connection.driver_class" value="org.h2.driver" /> <property name="hibernate.connection.username" value="root" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.format_sql" value="false" /> </properties> </persistence-unit> </persistence> i don't use other config file (e.g. hibernate.cfg.xml).
i'd appreciate clue why takes long.
thanks.
update:
it has started running fast (<2 seconds). i'm thinking there event waiting for. of talk network?
Comments
Post a Comment