Sql commands do not complete - hangs in console - hibernate -
what wrong code? sql command not complete, show_sql, able see first sql command issued, , left hanging out there indefinitely - program not proceed.
public class persondao { private configuration configuration; private sessionfactory sessionfactory; private session session; public persondao () { configuration = new configuration().configure(); sessionfactory = configuration.buildsessionfactory(); } public person addperson(person p) { transaction transaction = null; try { session = sessionfactory.opensession(); transaction = session.begintransaction(); system.out.println("before person add"); session.save(p); system.out.println("person added"); transaction.commit(); } catch (exception e) { e.printstacktrace(); } { session.flush(); session.close(); } return p; } @suppresswarnings("finally") public boolean deleteperson(long personid) { boolean issuccessful = false; transaction tx = null; try { session = sessionfactory.opensession(); tx = session.begintransaction(); object persistentinstance = session.load(person.class, personid); if (persistentinstance != null) { ((person)persistentinstance).getresponses().clear(); ((person)persistentinstance).getownedevents().clear(); session.delete(persistentinstance); } session.gettransaction().commit(); } catch (exception e) { tx.rollback(); issuccessful = false; e.printstacktrace(); } { session.flush(); session.close(); return issuccessful; } }
you need configure hibernate.cfg.xml file
configuration=new configuration(); configuration.configure("hibernate.cfg.xml");
Comments
Post a Comment