title: Container managed transcation (CMT) in hibernate + EJB
body: <p>The <a href="https://docs.jboss.org/hibernate/orm/4.0/devguide/en-US/html/ch02.html#d0e1472" rel="nofollow">hibernate documentation</a> says:</p>
  
  <blockquote>
    <p>With CMT, transaction demarcation is declared in session bean deployment descriptors, rather than performed in a programmatic manner.</p>
  </blockquote>
  
  <p>but I can't find any complete example on how to do this. </p>
  
  <p>This is what I have in mind my code should look like:</p>
  
  <pre><code>@Stateless
  public class Dao{
  
    @Inject // or some other annotation
    private SessionFactory factory;
  
    public void doDaoStuff(){
      Object obj = factory.getCurrentSession().get(Entity.class, "Id");
      // do something with obj
      return;
    }
  }
  </code></pre>
  
  <p>It is free from all the boilerplate that hibernate has as transaction should be started, committed and roll backed by container. </p>
  
  <p>So, Is it possible to do this? Although the documentation says that required declarations should be specified in <strong>bean deployment descriptors</strong>, doing it with annotations would be great.</p>