Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How to close Hibernate on exiting application?
PostPosted: Tue Feb 14, 2017 10:25 am 
Newbie

Joined: Tue Feb 14, 2017 10:19 am
Posts: 2
I am beginning with hibernate and JPA and I have been following several tutorials on JPA with eclipse link on Netbeans.

However, while still working on Netbeans I downloaded the hibernate-release-5.2.7.Final.zip manually from Hibernate web page and as stated here: http://docs.jboss.org/hibernate/orm/5.2 ... _artifacts.

I added the lib/required directory and the lib/jpa-metamodel-generator/ to my java application and mysql-connector jar. After that, I created my persistence.xml as in gist.

Then I created a sample Entity Prueba and I added a JPA ControllerClass from Entity through NetBeans wizard next, to that I created a quick Dao for testing Hibernate.

After creating my main class everything works fine the object is added to MySQL but the app doesn't close on finish I show the log and everything on gist https://gist.github.com/Paulwerito/111b ... c0452b8b2e


Top
 Profile  
 
 Post subject: Re: Java Hibernate JPA app adds objects to the database but the
PostPosted: Tue Feb 14, 2017 11:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1515
That's because you didn't close the EntityManagerFactory.

Add the following line

Code:
pbdao.destroy();


at the end of your test code:

Code:
public static void main(String[] args) {
        Prueba pb = new Prueba();
        PruebaDao pbdao = new PruebaDao();
       
        pb.setNombre("elexit");
       
        pbdao.addPrueba(pb);

        pbdao.destroy();               
}


where the destroy method in PruebaDao looks like this:

Code:
public void destroy() {
        this.em.close();
}

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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.