Classes and persistence.xml below. The problem is: entityManager is coming NULL.
@ManagedBean(name="pessoaController")
@SessionScoped
public class PessoaController{
private List<Pessoa> pessoas = new ArrayList<Pessoa>();
public PessoaController() {
new PessoaHome().findById(1);
}
public List<Pessoa> getPessoas(){
return pessoas;
}
public void setPessoas(List<Pessoa> pessoas){
this.pessoas = pessoas;
}
}
@Stateless
public class PessoaHome {
private static final Log log = LogFactory.getLog(PessoaHome.class);
@PersistenceContext
private EntityManager entityManager;
public void persist(Pessoa transientInstance) {
log.debug("persisting Pessoa instance");
try {
entityManager.persist(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
public void remove(Pessoa persistentInstance) {
log.debug("removing Pessoa instance");
try {
entityManager.remove(persistentInstance);
log.debug("remove successful");
} catch (RuntimeException re) {
log.error("remove failed", re);
throw re;
}
}
public Pessoa merge(Pessoa detachedInstance) {
log.debug("merging Pessoa instance");
try {
Pessoa result = entityManager.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public Pessoa findById(int id) {
log.debug("getting Pessoa instance with id: " + id);
try {
Pessoa instance = entityManager.find(Pessoa.class, id);
log.debug("get successful");
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
<persistence-unit name="postgresDS" transaction-type="JTA">
<jta-data-source>java:/postgresDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="none" />
</properties>
</persistence-unit>