I was reading a book regarding EJB 3.0 and it says that stateful session bean should be looked up using JNDI.
I have an stateful session bean as follows:
@Local
@Stateful
public class JpaDao {
@PersistenceContext(unitName="EmployeeService")
EntityManager em;
public EntityManager getEntityManager() {
return em;
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void addEmployee(String name, String lastName) {
Customer cust = new Customer();
.....................
....
In a JSF managed bean I did as follows:
Context ctx = new InitialContext();
JpaDao jpa = (JpaDao)ctx.lookup("java:comp/env/JpaDao");
But It didnt find anything. Why so ?
I opened wildfly cli client and saw jndi tree: subsystem=naming:jndi-view()
"applications" => {
"JavaServerFaces-1.0.war" => {
"java:app" => {
"AppName" => {
"class-name" => "java.lang.String",
"value" => "JavaServerFaces-1.0"
},
"env" => {
"class-name" => "org.jboss.as.naming.NamingContext",
"value" => "env"
},
"JavaServerFaces-1.0" => {
"class-name" => "javax.naming.Context",
"children" => {
"JpaDao" => {
"class-name" => "com.deluxe.common.dao.JpaDao",
"value" => "?"
},
"JpaDao!com.deluxe.common.dao.JpaDao" => {
"class-name" => "com.deluxe.common.dao.JpaDao",
"value" => "?"
}
}
}
},
"modules" => undefined
},
It does show an entry for JpaDao, then why JNDI lookup doesn't return anything.