title: Tapestry services implemetation with Hibernate usage
body: <p>I'm talking about T5, Java 1.7.</p>
  
  <p>I can not find any enough detailed tutorial about using hibernate inside Tapestry services.
  What I need is to create Tapestry service which could deal with hibernate independently. This could be scheduler service, for example.
  This service will deal with some objects and their state in DB, and work in background of application.</p>
  
  <p>The question is, how correctly bind it with Hibernate? Which object of Hibernate should be injected for further work inside this Service?</p>
  
  <hr>
  
  <p>The current approach is to inject inside this service a <code>HibernateSessionSource</code> object (passing its instance through constructor of service), and then manually create sessions, begin the transactions and so on. E.g.:</p>
  
  <pre><code>public synchronized void deleteJob(long id) {
      Session session = hss.create();
      JobItem job = (JobItem) session.get(JobItem.class, id);
      if (job != null) {
          Transaction tx = session.beginTransaction();
          try {
              session.delete(job);
              tx.commit();
          } catch (HibernateException e) {
              tx.rollback();
          } finally {
              session.close();
          }
      }
  }
  </code></pre>
  
  <p>It looks very ugly, not in style of Tapestry. What it is the smart approach?</p>