我的項目中有2個ejb-module,ejb-module1和ejb-module2。 EJB-模塊1包含實體clases和持久性單元,有一個實體管理器EJB這樣的:如何從其他EJBModule注入entityManager到EJB
@Stateful
public class ErpTools implements ErpToolsLocal {
@PersistenceContext(unitName = "erp-ejbPU")
private EntityManager em;
public EntityManager getEm() {
return em;
}
public void setEm(EntityManager em) {
this.em = em;
}
在ejb-模塊2,我有其他的EJB需要使用實體管理器從EJB-模塊1, 我試着用對此,
String ejbql = "SELECT e from CtEmpresaCliente e ORDER BY e.idCliente ASC";
Query query = this.erpTools.getEm().createQuery(ejbql);
empresaClientes = query.getResultList();
但發送此異常:
"Unable to retrieve EntityManagerFactory for unitName erp-ejbPU"
debuging in this point Query query = this.erpTools.getEm().createQuery(ejbql);
this.erpTools.getEm() is not null.
筆記:Netbeans
,JPA
,JEE6
,EJB 3.1
你有一個persistence.xml的「erp-ejbPU」作爲持久性單元名嗎? – fiso 2013-03-19 15:12:12
yes: dsct jta-data-source> false <排除未列出的類> persistence-unit> –
meyquel
2013-03-19 15:21:54
這很奇怪,因爲它看起來好像沒有采用persistence.xml。 META-INF文件夾中有persistence.xml文件嗎? – fiso 2013-03-19 15:45:07