hibernate - New database connection after build application -


i have strange problem creating jpa entity manager after every rebuild application. in application have static class entitymanger dao classes:

import javax.persistence.entitymanager; import play.db.jpa.jpa;  public class appentitymanager {      private static entitymanager em = jpa.em("default");      public static entitymanager getinstance() {              return em;     }  } 

example how use class:

public static user getuserbyusername(string username) {         query query = appentitymanager.getinstance().createquery("select u user u u.username = :username", user.class);         query.setparameter("username", username);         try {             return (user) query.getsingleresult();         } catch (exception e) {             e.printstacktrace();             return null;         }      } 

the first time create 5 connections database. after recompiling application each time added on same connection. can not understand why , how fix it. please show example of how use jpa + hibernate correctly.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -