don't waste your time while looking for public jndi that belong to your sessinbean while calling it locally in weblogic environment. weblogic don't support jndi with local beans even if you type mappped name in that class like
if you call this bean with in a web project that in same ear (same jvm), you must define it in your web xml like
if you define it like above, then you can call it with like this code.
package tr.gov.ibb.core.model.session;
import java.util.List;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;
import tr.gov.ibb.core.model.entity.Musteri;
@Stateful(name = "TestBean", mappedName = "ejb/TestBean")
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class TestBean implements TestRemote,TestLocal {
@PersistenceContext(unitName = "CoreContextWithoutEUS", type = PersistenceContextType.EXTENDED)
private EntityManager em;
public ListgetMusteriList() {
try {
Query query = em.createQuery("SELECT m from Musteri m where m.musteriKodu in (2234988,2234989)");
return query.getResultList();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Remove
public void destroy() {
System.out.println("TestBean destroyed");
}
}
if you call this bean with in a web project that in same ear (same jvm), you must define it in your web xml like
ejb/TestBean
tr.gov.ibb.core.model.session.TestLocal
if you define it like above, then you can call it with like this code.
public class TestConroller extends BaseBean {
public TestConroller() {
try {
testLocal = (TestLocal) new InitialContext().lookup("java:comp/env/ejb/TestBean");
System.out.println("testRemote " + testRemote);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public TestLocal testLocal;
}
Yorumlar
Yorum Gönder