File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Unable to register JNDI Name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Unable to register JNDI Name" Watch "Unable to register JNDI Name" New topic

Unable to register JNDI Name

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 850
I am deploying 2 stateless session bean's under 1 jar.

Under EJB Module's, i am able to see both Stateless Session Bean's.

However when i see under JNDI tree, only 1 bean has it's mappedName. I am not able to make out why the other bean doesn't has mappedName getting registered under JNDI tree. this class i am able to see it's JNDI name in GlassFish)

package Pack;

import java.util.List;

import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.EntityResult;

import Factory.CarEAO;
import Factory.EAOFactory;
import Factory.JPAEAOFactory;
* Session Bean implementation class CarCreatorBean
@Stateless(name="StatelessSessionBean", mappedName="ejb/SimpleJNDIName")
@SqlResultSetMapping(name = "CarResults",
entities = @EntityResult(entityClass = Pack.Car.class))

public class CarCreatorBean implements CarCreator {

* Default constructor.
public CarCreatorBean() {
// TODO Auto-generated constructor stub

@PersistenceContext(unitName ="actionBazaar")
private EntityManager entityManager;

public void addCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
System.out.println("Inside addCarComponents" + entityManager);
public void addMergeCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
public void undoCarComponents(String horn, String steering, String wheel){
Car car = new Car("horn", "steering", "wheel");
public void deleteCarComponents(Long id){
entityManager.remove(entityManager.find(Car.class, id));
public Car retrieveItem(Long id){
Car car = entityManager.find(Car.class, id);
return car;
public List sqlQuery(){
// System.out.println("Inside the sqlQuery method");
// Query query = entityManager.createQuery("select c from Car c");

Query query = entityManager.createNamedQuery("findCar");
query.setParameter("steering", "steering");
return query.getResultList();

public List sqlQuery1(){
Query query = entityManager.createNamedQuery("findCar1");
query.setParameter(1, "horn");
// set the maximum no. of objects to be retrieved.
// set the initial position for the first result being retrieved.
return query.getResultList();

public List nativeResult(){
Query query = entityManager.createNativeQuery("select * from Car");
return query.getResultList();

public void carFactory(String steering, String horn, String wheel){
CarEAO carEAO = EAOFactory.jpa.getCarEAO();
carEAO.addCar(steering, horn, wheel);

----------------------------------------- this class unable to see it's mappedName in JNDI tree, why?)

package Factory;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.sql.DataSource;

import Pack.Car;

@Stateless(name="StatelessSessionBean1", mappedName="ejb/SimpleJNDIName1")
public class CarEAOImpl implements CarEAO{

public CarEAOImpl(){

//@PersistenceContext(unitName ="actionBazaar")
// private EntityManager entityManager;

private EntityManagerFactory emf;

//private EntityManager getEntityManager() throws NamingException{
// return entityManager;
public void addCar(String steering, String horn, String wheel) {
//EntityManager em;

//entityManager = getEntityManager();
EntityManager entityManager = emf.createEntityManager();
System.out.println("getEntityManager() =" + entityManager);
Car c = new Car(steering, horn, wheel);



SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog-
I agree. Here's the link:
subject: Unable to register JNDI Name
jQuery in Action, 3rd edition