Hi!
To let your application server inject an EntityManager in your bean write:
Code:
@Stateless
public class MySimpleBean implements MySimpleBeanRemote {
@PersistenceContext(unitName="the name of your persitence unit")
private EntiyManager entityManager
...
}
If your are using jboss, the session can be injected directly:
Code:
@Stateless
public class MySimpleBean implements MySimpleBeanRemote {
@PersistenceContext(unitName="the name of your persitence unit")
Session session
...
}
If your aren't using JBOSS but you want to work with a session instead of an entiymanager do it right this:
Code:
@Stateless
public class MySimpleBean implements MySimpleBeanRemote {
private Session session
@PersistenceContext(unitName="the name of your persitence unit")
public void setEntityManager() {
session = ((HibernateEntityManager)entityManager).getSession();
}
...
}