0

I have written a beginner-level program using Hibernate Search 4. Whenever I run the program the required transaction is performed (e.g. saving records in database), but the program does not terminate. It seems that a thread is running in the background but I can't figure out which thread is running or why.

public static void main(String[] args) {

    Session sess= HibernateUtil.getSf().getCurrentSession();
    FullTextSession fts = org.hibernate.search.Search.getFullTextSession(sess);

    Item it= new Item();
    it.setTitle("Batman");
    it.setDescription("bat man super hero ");
    Item it2= new Item();
    it2.setTitle("Mario");
    it2.setDescription("super mario was game ");

    Transaction t= fts.beginTransaction();
    fts.save(it);
    fts.save(it2);
    t.commit();
Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
Naman Jain
  • 231
  • 1
  • 2
  • 8
  • Use a debugger, pick any of the free ones available for all common platforms. Eclipse IDE, Netbeans IDE, Intellij. In the debugger you should be able to see an active Thread list and set breakpoint in 'static void main(String[])' method to see what happens when that returned. – Darryl Miles Sep 21 '12 at 07:13

1 Answers1

1

The Hibernate SessionFactory needs to be closed.

HibernateUtil.getSf().close();

When not using Hibernate Search you likely didn't notice this requirement as ORM doesn't run any background threads, but this has always been a requirement to make sure everything is orderly cleaned up.

Sanne
  • 6,027
  • 19
  • 34