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

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -