java - Hibernate test does not finish -


i have java application connection mysql database via hibernate.

i have written test testing connection database, never ends. 2 threads running, code i've written in test executed. 2 threads are:

thread [pool-1-thread-1] (running)   thread [destroyjavavm] (running)     

the following testfile:

vote v1 = new vote(0, "abc"); vote v2 = new vote(1, "def"); candidate c1 = new candidate(0, "first candidate"); timestamp t = new timestamp(0, 123456l);  entitymanager entmgr = entitymanagerutil.getentitymanagerfactory().createentitymanager(); entitytransaction transaction = entmgr.gettransaction(); transaction.begin();  voterepository vr = new voterepository(entmgr); entmgr.persist(v1); entmgr.persist(v2);  candidaterepository cr = new candidaterepository(entmgr); entmgr.persist(c1);  timestamprepository tr = new timestamprepository(entmgr); entmgr.persist(t);  transaction.commit(); entmgr.close(); 

my persistence.xml looks this:

<provider>org.hibernate.jpa.hibernatepersistenceprovider</provider>     <!-- tell jpa/hibernate our @entity objects -->     <class>org.evoting.database.entities.candidate</class>     <class>org.evoting.database.entities.timestamp</class>     <class>org.evoting.database.entities.vote</class>  <properties>     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver" />     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://url" />     <property name="javax.persistence.jdbc.user" value="***" />     <property name="javax.persistence.jdbc.password" value="***" />     <property name="hibernate.dialect" value="org.hibernate.dialect.mysqldialect" />      <!-- update database schema on startup: "update"; "validate" check -->     <property name="hibernate.hbm2ddl.auto" value="update" />      <!-- echo executed sql stdout -->     <property name="hibernate.show_sql" value="true" />      <!-- disable second-level cache -->     <property name="hibernate.cache.provider_class" value="org.hibernate.cache.nocacheprovicer" />      <property name="hibernate.format_sql" value="true" />     <property name="hibernate.transaction.flush_before_completion" value="true" />     <property name="hibernate.connection.autocommit" value="false" />     <property name="hibernate.connection.release_mode" value="after_transaction" /> </properties> 

what can cause test never finish?

i found out had close entitymanagerfactory in order test finish. instead of

entmgr.close(); 

i should write

entmgr.getentitymanagerfactory.close(); 

with new line test finishes , happy :)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -